Skip to content

Commit

Permalink
Add official partial support/test for GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jun 24, 2017
1 parent 657ada5 commit 10b4255
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# shorten-repo-url [![Build Status](https://travis-ci.org/bfred-it/shorten-repo-url.svg?branch=master)](https://travis-ci.org/bfred-it/shorten-repo-url)

> Shorten GitHub links like GitHub shortens Issues and Commit links. Used on [refined-github](https://github.com/sindresorhus/refined-github)
> Shorten GitHub/GitLab links like GitHub shortens Issues and Commit links. Used on [refined-github](https://github.com/sindresorhus/refined-github)
![Demo](https://user-images.githubusercontent.com/1402241/27252232-8fdf8ed0-538b-11e7-8f19-12d317c9cd32.png)

Look at [the tests](https://github.com/bfred-it/shorten-repo-url/blob/master/test.js) to see what each URL is shortened to. GitLab URLs are untested but they seem compatible. PRs welcome to add support/tests for GitLab and BitBucket URLs.
Look at [the tests](https://github.com/bfred-it/shorten-repo-url/blob/master/test.js) to see what each URL is shortened to. GitLab URLs are mostly compatible. Not all are shortened. PRs welcome to add support/tests for more GitLab and BitBucket URLs, unless they just become too much.

It works on any domain, so Enterprise and Community Editions are supported.


## Install
Expand Down
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {URL} = require('url');

const patchDiffRegex = /[.](patch|diff)$/;
const releaseRegex = /releases[/]tag[/]([^/]+)/;
const releaseRegex = /(?:releases[/]tag|tags)[/]([^/]+)/;
const labelRegex = /labels[/]([^/]+)/;
const releaseArchiveRegex = /archive[/](.+)([.]zip|[.]tar[.]gz)/;
const releaseDownloadRegex = /releases[/]download[/]([^/]+)[/](.+)/;
Expand Down Expand Up @@ -31,7 +31,7 @@ const reservedPaths = [
'open-source',
'marketplace',
'organizations',
'notifications'
'notifications',
];

function styleRevision(revision) {
Expand All @@ -51,6 +51,10 @@ function joinValues(array, delimiter = '/') {
}

function shortenURL(href, currentUrl = 'https://github.com') {
if (!href) {
return;
}

currentUrl = new URL(currentUrl);
const currentRepo = currentUrl.pathname.slice(1).split('/', 2).join('/');

Expand All @@ -61,13 +65,13 @@ function shortenURL(href, currentUrl = 'https://github.com') {
origin,
pathname,
search,
hash
hash,
} = new URL(href);

const isRaw = [
'https://raw.githubusercontent.com',
'https://cdn.rawgit.com',
'https://rawgit.com'
'https://rawgit.com',
].includes(origin);

let [
Expand Down Expand Up @@ -105,7 +109,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
'tree',
'blob',
'blame',
'commits'
'commits',
].includes(type);

const repoUrl = isThisRepo ? '' : `${user}/${repo}`;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shorten-repo-url",
"version": "1.1.0",
"description": "Shorten GitHub URLs like GitHub shortens Issues and Commit URLs",
"description": "Shorten GitHub/GitLab URLs like GitHub shortens Issues and Commit URLs",
"license": "MIT",
"repository": "bfred-it/shorten-repo-url",
"author": "Federico Brigante <github@bfred.it> (bfred.it)",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"xo": {
"rules": {
"comma-dangle": ["error", "only-multiline"]
"comma-dangle": ["error", "always-multiline"]
}
}
}

0 comments on commit 10b4255

Please sign in to comment.