Skip to content

Commit

Permalink
add coding.net token support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangnew committed Mar 14, 2020
1 parent a4d02c9 commit fa854cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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** 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 === 'e.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

0 comments on commit fa854cf

Please sign in to comment.