diff --git a/README.md b/README.md index dd22911..79a47ed 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ deploy: While this plugin can parse authentication token from the config, only use this method if you are sure the config will not be committed, including to a private repo. A more secure approach is to add it to the CI as an environment variable, then simply add the name of the environment variable to this plugin's config (e.g. `$GITHUB_TOKEN`). +Token format can be pure token like `this_is_token_string` or can be linke `username:password`` format. + Additional guides: - Create a GitHub Personal Access Token. [[Link]](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) diff --git a/lib/parse_config.js b/lib/parse_config.js index 08a79d7..474a5b2 100644 --- a/lib/parse_config.js +++ b/lib/parse_config.js @@ -1,6 +1,7 @@ 'use strict'; const rRepoURL = /^(?:(git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/; // eslint-disable-line no-useless-escape +const rUserPassword = /([^:]+)(?::)(.+)/; // eslint-disable-line no-useless-escape const rGithubPage = /\.github\.(io|com)$/; const { URL } = require('url'); @@ -30,11 +31,16 @@ function parseObjRepo(repo) { } else { userToken = configToken; } - repoUrl.username = userToken; + if (rUserPassword.test(userToken)) { + const match = userToken.match(rUserPassword); + repoUrl.username = match[1]; + repoUrl.password = match[2]; + } else { + repoUrl.username = userToken; + } url = repoUrl.href; } } - return { url: url, branch: branch || 'master'