Skip to content

Commit

Permalink
fix: use project path for API calls again (#580)
Browse files Browse the repository at this point in the history
Revert "fix: use numeric project ID for API calls"
  • Loading branch information
fgreinacher committed Aug 9, 2023
1 parent fd9ce92 commit b0357dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/get-repo-id.js
@@ -1,9 +1,9 @@
import parseUrl from "parse-url";
import escapeStringRegexp from "escape-string-regexp";

export default ({ envCi: { service } = {}, env: { CI_PROJECT_ID } }, gitlabUrl, repositoryUrl) =>
service === "gitlab" && CI_PROJECT_ID
? CI_PROJECT_ID
export default ({ envCi: { service } = {}, env: { CI_PROJECT_PATH } }, gitlabUrl, repositoryUrl) =>
service === "gitlab" && CI_PROJECT_PATH
? CI_PROJECT_PATH
: parseUrl(repositoryUrl)
.pathname.replace(new RegExp(`^${escapeStringRegexp(parseUrl(gitlabUrl).pathname)}`), "")
.replace(/^\//, "")
Expand Down
8 changes: 4 additions & 4 deletions test/get-repo-id.test.js
Expand Up @@ -41,18 +41,18 @@ test("Parse repo id with organization and subgroup", (t) => {
test("Get repo id from GitLab CI", (t) => {
t.is(
getRepoId(
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_ID: "123" } },
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } },
"https://gitlbab.com",
"https://gitlab.com/owner/repo.git"
),
"123"
"other-owner/other-repo"
);
});

test("Ignore CI_PROJECT_ID if not on GitLab CI", (t) => {
test("Ignore CI_PROJECT_PATH if not on GitLab CI", (t) => {
t.is(
getRepoId(
{ envCi: { service: "travis" }, env: { CI_PROJECT_ID: "123" } },
{ envCi: { service: "travis" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } },
"https://gitlbab.com",
"https://gitlab.com/owner/repo.git"
),
Expand Down

0 comments on commit b0357dc

Please sign in to comment.