Skip to content

Commit fa854cf

Browse files
committed
add coding.net token support
1 parent a4d02c9 commit fa854cf

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ deploy:
5757
[repo_name]:
5858
url: <repository url>
5959
branch: [branch]
60+
token: [token]
61+
token_name: [token_name] # for coding.net
6062
```
6163
6264
- **repo**: Repository settings, or plain url of your repo
@@ -66,6 +68,7 @@ deploy:
6668
- Defaults to `coding-pages` on Coding.net.
6769
- Otherwise defaults to `master`.
6870
- **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).
71+
- **token_name** coding.net needs token name and token to authenticate. [More details](#deploy-with-token)
6972
- **repo_name**: Unique name when deploying to multiple repositories.
7073
* Example:
7174
``` yaml
@@ -111,6 +114,7 @@ While this plugin can parse authentication token from the config, only use this
111114
Additional guides:
112115

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

116120
## How it works

lib/parse_config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { URL } = require('url');
77
function parseObjRepo(repo) {
88
let url = repo.url;
99
let branch = repo.branch;
10+
let token_name = repo.token_name;
1011
let configToken = repo.token;
1112

1213
if (!branch) {
@@ -30,7 +31,12 @@ function parseObjRepo(repo) {
3031
} else {
3132
userToken = configToken;
3233
}
33-
repoUrl.username = userToken;
34+
if (token_name && repoUrl.host === 'e.coding.net') {
35+
repoUrl.username = token_name;
36+
repoUrl.password = userToken;
37+
} else {
38+
repoUrl.username = userToken;
39+
}
3440
url = repoUrl.href;
3541
}
3642
}

test/parse_config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ describe('parse config', function() {
220220
delete process.env.GIT_TOKEN;
221221
});
222222

223+
it('coding.net token with token_name', function() {
224+
process.env.CODING_TOKEN = 'env_token';
225+
parseConfig({
226+
repo: {
227+
coding: {
228+
url: 'https://e.coding.net/hexojs/hexojs.git',
229+
branch: 'site',
230+
token: '$CODING_TOKEN',
231+
token_name: 'coding_token_name'
232+
}
233+
}
234+
})[0].should.eql(
235+
{url: 'https://coding_token_name:env_token@e.coding.net/hexojs/hexojs.git', branch: 'site'}
236+
);
237+
238+
delete process.env.CODING_TOKEN;
239+
});
240+
223241
it('fail to read env var token', function() {
224242

225243
// http

0 commit comments

Comments
 (0)