Skip to content

Commit

Permalink
Support a dot in repo names.
Browse files Browse the repository at this point in the history
Currently Ebi parses https://github.com/financial-times/ft.com-cdn
as https://github.com/financial-times/ft, which redirects and returns
files from https://github.com/financial-times/fta

This commit updates `GITHUB_REPO_REGEX` to match dots in the repo
name. This however means `.git` is also matched, so `.git` is
removed first as part of the `extractOwnerAndRepo` method.

_Note: My previous attempt to do everything in a regex, without removing
`.git` first didn't go great. I ended up with the repo name either being
in group 3 or 4:
`^(?:\S*github\.com(?:\/|:))?([\w-]+)\/(([\w-\.]+)(?:\.git)|([\w-\.]+))`_
  • Loading branch information
notlee committed Nov 6, 2019
1 parent 4803109 commit 8cf1fed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/github-helpers.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const GITHUB_REPO_REGEX = /^(?:\S*github\.com(?:\/|:))?([\w-]+)\/([\w-]+)/;
const GITHUB_REPO_REGEX = /^(?:\S*github\.com(?:\/|:))?([\w-]+)\/([\w-\.]+)/;

/**
* Array of repo string patterns supported by `extractOwnerAndRepo`.
*
* @type {Array<string>}
*/
const SUPPORTED_REPO_STRING_PATTERNS = [
'github-organization/github-repo-name',
'github.com/github-organization/github-repo-name',
'subdomain.github.com/github-organization/github-repo-name',
'https://github.com/github-organization/github-repo-name',
'https://github.com/github-organization/github-repo-name/blob/master',
'https://github.com/github-organization/github-repo-name.git',
'git+https://github.com/github-organization/github-repo-name.git',
'[email protected]:github-organization/github-repo-name.git'
'github-organization/github-repo.name',
'github.com/github-organization/github-repo.name',
'subdomain.github.com/github-organization/github-repo.name',
'https://github.com/github-organization/github-repo.name',
'https://github.com/github-organization/github-repo.name/blob/master',
'https://github.com/github-organization/github-repo.name.git',
'git+https://github.com/github-organization/github-repo.name.git',
'[email protected]:github-organization/github-repo.name.git'
];

/**
Expand All @@ -24,6 +24,9 @@ const SUPPORTED_REPO_STRING_PATTERNS = [
* @returns {object} - Properties: owner, repo
*/
function extractOwnerAndRepo(githubRepoString) {
// Remove trailing .git extension
githubRepoString = githubRepoString.replace(/.git$/, '');
// Match owner and repo
const matches = GITHUB_REPO_REGEX.exec(githubRepoString);

if (matches === null) {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/github-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
} = require('../../lib/github-helpers');

const expectedOwner = 'github-organization';
const expectedRepo = 'github-repo-name';
const expectedRepo = 'github-repo.name';

const supportedRepoStrings = SUPPORTED_REPO_STRING_PATTERNS;

Expand Down

0 comments on commit 8cf1fed

Please sign in to comment.