Skip to content

Commit

Permalink
fix: improve code for get gitlab repo info
Browse files Browse the repository at this point in the history
  • Loading branch information
neo committed Nov 5, 2020
1 parent 6122a7e commit 5ff49f5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/common/adapters/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,25 @@ class Gitlab extends PjaxAdapter {

let pathname = window.location.pathname;
// get project name first
const projectName = $('body').data('project');
const { group, project } = $('body').data();

const replacePath = pathname.replace(/\/-\/([^/]+)?/, '/$1');

// dynamic regex
let match = replacePath.match(new RegExp(`((?:[^/]+\\/)+)${projectName}(?:\\/([^/]+))`));
let match = replacePath.match(new RegExp(`((?:[^/]+\\/)+)${group}/${project}(\\/([^/]+))?`));

if (!match) {
return cb();
}

let reponame = projectName;
let reponame = project;

const usernameArr = match[1].split('/').filter(Boolean);
let type = match[2] || '';

usernameArr.push(group);
const username = usernameArr.join('/');

let type = match[2] || '';

// Not a repository, skip
if (~GL_RESERVED_USER_NAMES.indexOf(username) || ~GL_RESERVED_REPO_NAMES.indexOf(reponame) || ~GL_RESERVED_TYPES.indexOf(type)) {
return cb();
Expand Down

0 comments on commit 5ff49f5

Please sign in to comment.