Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 21, 2019
2 parents 8e9d3d1 + 848d258 commit 9e099f3
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
- 12
- 10
- 8.3
- 8.16

# Trigger a push build on release and greenkeeper branches + PRs build on every branches
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
Expand Down
4 changes: 2 additions & 2 deletions lib/add-channel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const parseGithubUrl = require('parse-github-url');
const debug = require('debug')('semantic-release:github');
const {RELEASE_NAME} = require('./definitions/constants');
const parseGithubUrl = require('./parse-github-url');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
const isPrerelease = require('./is-prerelease');
Expand All @@ -14,7 +14,7 @@ module.exports = async (pluginConfig, context) => {
logger,
} = context;
const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context);
const {name: repo, owner} = parseGithubUrl(repositoryUrl);
const {owner, repo} = parseGithubUrl(repositoryUrl);
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
let releaseId;

Expand Down
5 changes: 2 additions & 3 deletions lib/fail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {template} = require('lodash');
const parseGithubUrl = require('parse-github-url');
const debug = require('debug')('semantic-release:github');
const parseGithubUrl = require('./parse-github-url');
const {ISSUE_ID} = require('./definitions/constants');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
Expand All @@ -23,9 +23,8 @@ module.exports = async (pluginConfig, context) => {
logger.log('Skip issue creation.');
} else {
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
let {name: repo, owner} = parseGithubUrl(repositoryUrl);
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
[owner, repo] = (await github.repos.get({repo, owner})).data.full_name.split('/');
const [owner, repo] = (await github.repos.get(parseGithubUrl(repositoryUrl))).data.full_name.split('/');
const body = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors);
const [srIssue] = await findSRIssues(github, failTitle, owner, repo);

Expand Down
13 changes: 13 additions & 0 deletions lib/parse-github-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {URL} = require('url');

module.exports = repositoryUrl => {
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*?)$/.exec(repositoryUrl) || [];
try {
const [, owner, repo] = /^\/([^/]+)?\/?(.+?)(?:\.git)?$/.exec(
new URL(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl).pathname
);
return {owner, repo};
} catch (_) {
return {};
}
};
4 changes: 2 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {basename, extname, resolve} = require('path');
const {stat, readFile} = require('fs-extra');
const {isPlainObject, template} = require('lodash');
const parseGithubUrl = require('parse-github-url');
const mime = require('mime');
const debug = require('debug')('semantic-release:github');
const {RELEASE_NAME} = require('./definitions/constants');
const parseGithubUrl = require('./parse-github-url');
const globAssets = require('./glob-assets.js');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
Expand All @@ -19,7 +19,7 @@ module.exports = async (pluginConfig, context) => {
logger,
} = context;
const {githubToken, githubUrl, githubApiPathPrefix, proxy, assets} = resolveConfig(pluginConfig, context);
const {name: repo, owner} = parseGithubUrl(repositoryUrl);
const {owner, repo} = parseGithubUrl(repositoryUrl);
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
const release = {owner, repo, tag_name: gitTag, name, body: notes, prerelease: isPrerelease(branch)};

Expand Down
7 changes: 2 additions & 5 deletions lib/success.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const {isNil, uniqBy, template, flatten} = require('lodash');
const parseGithubUrl = require('parse-github-url');
const pFilter = require('p-filter');
const AggregateError = require('aggregate-error');
const issueParser = require('issue-parser');
const debug = require('debug')('semantic-release:github');
const parseGithubUrl = require('./parse-github-url');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
const getSearchQueries = require('./get-search-queries');
Expand All @@ -30,11 +30,8 @@ module.exports = async (pluginConfig, context) => {
} = resolveConfig(pluginConfig, context);

const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
const parsedUrl = parseGithubUrl(repositoryUrl);
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
const [owner, repo] = (await github.repos.get({repo: parsedUrl.name, owner: parsedUrl.owner})).data.full_name.split(
'/'
);
const [owner, repo] = (await github.repos.get(parseGithubUrl(repositoryUrl))).data.full_name.split('/');

const errors = [];

Expand Down
4 changes: 2 additions & 2 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {isString, isPlainObject, isNil, isArray, isNumber} = require('lodash');
const parseGithubUrl = require('parse-github-url');
const urlJoin = require('url-join');
const AggregateError = require('aggregate-error');
const parseGithubUrl = require('./parse-github-url');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
const getError = require('./get-error');
Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = async (pluginConfig, context) => {
logger.log('Verify GitHub authentication');
}

const {name: repo, owner} = parseGithubUrl(repositoryUrl);
const {repo, owner} = parseGithubUrl(repositoryUrl);
if (!owner || !repo) {
errors.push(getError('EINVALIDGITHUBURL'));
} else if (githubToken && !errors.find(({code}) => code === 'EINVALIDPROXY')) {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
"globby": "^10.0.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^3.0.0",
"issue-parser": "^4.0.0",
"issue-parser": "^5.0.0",
"lodash": "^4.17.4",
"mime": "^2.4.3",
"p-filter": "^2.0.0",
"p-retry": "^4.0.0",
"parse-github-url": "^1.0.1",
"url-join": "^4.0.0"
},
"devDependencies": {
Expand All @@ -49,7 +48,7 @@
"xo": "^0.25.2"
},
"engines": {
"node": ">=8.3"
"node": ">=8.16"
},
"files": [
"lib",
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/mock-github.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nock from 'nock';

/**
* Retun a `nock` object setup to respond to a github authentication request. Other expectation and responses can be chained.
* Return a `nock` object setup to respond to a github authentication request. Other expectation and responses can be chained.
*
* @param {Object} [env={}] Environment variables.
* @param {String} [githubToken=env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN'] The github token to return in the authentication response.
Expand All @@ -21,7 +21,7 @@ export function authenticate(
}

/**
* Retun a `nock` object setup to respond to a github release upload request. Other expectation and responses can be chained.
* Return a `nock` object setup to respond to a github release upload request. Other expectation and responses can be chained.
*
* @param {Object} [env={}] Environment variables.
* @param {String} [githubToken=env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN'] The github token to return in the authentication response.
Expand Down
Loading

0 comments on commit 9e099f3

Please sign in to comment.