Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add coding.net token support #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ deploy:
[repo_name]:
url: <repository url>
branch: [branch]
token: [token]
token_name: [token_name] # for coding.net
```

- **repo**: Repository settings, or plain url of your repo
Expand All @@ -66,6 +68,7 @@ deploy:
- Defaults to `coding-pages` on Coding.net.
- Otherwise defaults to `master`.
- **token**: Optional token value to authenticate with the repo. Prefix with `$` to read token from environment variable (recommended). Repo must be a http(s) url. [More details](#deploy-with-token).
- **token_name**: Only valid for coding.net, coding.net needs token name and token to authenticate. [More details](#deploy-with-token)
- **repo_name**: Unique name when deploying to multiple repositories.
* Example:
``` yaml
Expand Down Expand Up @@ -111,6 +114,7 @@ While this plugin can parse authentication token from the config, only use this
Additional guides:

- Create a GitHub Personal Access Token. [[Link]](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line)
- Create a Coding Project Access Token. [[Link]](https://help.coding.net/docs/project/features/deploy-tokens.html)
- Add authentication token to Travis CI. [[Link]](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-settings)

## How it works
Expand Down
8 changes: 7 additions & 1 deletion lib/parse_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { URL } = require('url');
function parseObjRepo(repo) {
let url = repo.url;
let branch = repo.branch;
let token_name = repo.token_name;
let configToken = repo.token;

if (!branch) {
Expand All @@ -30,7 +31,12 @@ function parseObjRepo(repo) {
} else {
userToken = configToken;
}
repoUrl.username = userToken;
if (token_name && repoUrl.host.includes('coding.net')) {
repoUrl.username = token_name;
repoUrl.password = userToken;
} else {
repoUrl.username = userToken;
}
url = repoUrl.href;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/parse_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ describe('parse config', function() {
delete process.env.GIT_TOKEN;
});

it('coding.net token with token_name', function() {
process.env.CODING_TOKEN = 'env_token';
parseConfig({
repo: {
coding: {
url: 'https://e.coding.net/hexojs/hexojs.git',
branch: 'site',
token: '$CODING_TOKEN',
token_name: 'coding_token_name'
}
}
})[0].should.eql(
{url: 'https://coding_token_name:[email protected]/hexojs/hexojs.git', branch: 'site'}
);

delete process.env.CODING_TOKEN;
});

it('fail to read env var token', function() {

// http
Expand Down