Skip to content
Permalink
Browse files

add coding.net token support

  • Loading branch information
zhangnew committed Mar 14, 2020
1 parent a4d02c9 commit fa854cf7d28130299654e0b10ef270e4cda8c2b6
Showing with 29 additions and 1 deletion.
  1. +4 −0 README.md
  2. +7 −1 lib/parse_config.js
  3. +18 −0 test/parse_config.js
@@ -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
@@ -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
@@ -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
@@ -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) {
@@ -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;
}
}
@@ -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:env_token@e.coding.net/hexojs/hexojs.git', branch: 'site'}
);

delete process.env.CODING_TOKEN;
});

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

// http

0 comments on commit fa854cf

Please sign in to comment.
You can’t perform that action at this time.