From 93c4f3f062ce425f9e47814eb6b073aa877be3be Mon Sep 17 00:00:00 2001 From: neo Date: Sat, 27 Feb 2021 00:20:13 +0800 Subject: [PATCH 1/2] feat: add username and password token support --- README.md | 2 ++ lib/parse_config.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index afa6e8a..c3b4de7 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,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..d410369 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' From dc91248b3d0b51e7599f52d3d20b04ed99d76e47 Mon Sep 17 00:00:00 2001 From: neo Date: Sat, 27 Feb 2021 00:29:38 +0800 Subject: [PATCH 2/2] style: reformat the code --- lib/parse_config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/parse_config.js b/lib/parse_config.js index d410369..474a5b2 100644 --- a/lib/parse_config.js +++ b/lib/parse_config.js @@ -32,11 +32,11 @@ function parseObjRepo(repo) { userToken = configToken; } if (rUserPassword.test(userToken)) { - const match = userToken.match(rUserPassword); - repoUrl.username = match[1]; - repoUrl.password = match[2]; + const match = userToken.match(rUserPassword); + repoUrl.username = match[1]; + repoUrl.password = match[2]; } else { - repoUrl.username = userToken; + repoUrl.username = userToken; } url = repoUrl.href; }