diff --git a/README.md b/README.md index afa6e8a..fc4a3c1 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ deploy: [repo_name]: 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 diff --git a/lib/parse_config.js b/lib/parse_config.js index 8a09bcd..7bacb06 100644 --- a/lib/parse_config.js +++ b/lib/parse_config.js @@ -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; } } diff --git a/test/parse_config.js b/test/parse_config.js index 5276355..4dd3d42 100644 --- a/test/parse_config.js +++ b/test/parse_config.js @@ -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