-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: inline getProjectId / getProjectPath functions
- Loading branch information
1 parent
743ab0a
commit 2102ec3
Showing
5 changed files
with
188 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import test from "ava"; | ||
import getProjectContext from "../lib/get-project-context.js"; | ||
|
||
test("Parse project path with https URL", (t) => { | ||
t.is( | ||
getProjectContext({ env: {} }, "https://gitlbab.com", "https://api.gitlab.com", "https://gitlab.com/owner/repo.git") | ||
.projectPath, | ||
"owner/repo" | ||
); | ||
t.is( | ||
getProjectContext({ env: {} }, "https://gitlbab.com", "https://api.gitlab.com", "https://gitlab.com/owner/repo").projectPath, | ||
"owner/repo" | ||
); | ||
}); | ||
|
||
test("Parse project path with git URL", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlab.com", | ||
"https://api.gitlab.com", | ||
"git+ssh://[email protected]/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlab.com", | ||
"https://api.gitlab.com", | ||
"git+ssh://[email protected]/owner/repo" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
}); | ||
|
||
test("Parse project path with context in repo URL", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/context/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"git+ssh://[email protected]/context/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
}); | ||
|
||
test("Parse project path with context not in repo URL", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"git+ssh://[email protected]/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
}); | ||
|
||
test("Parse project path with organization and subgroup", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/orga/subgroup/owner/repo.git" | ||
).projectPath, | ||
"orga/subgroup/owner/repo" | ||
); | ||
t.is( | ||
getProjectContext( | ||
{ env: {} }, | ||
"https://gitlbab.com/context", | ||
"https://api.gitlab.com", | ||
"git+ssh://[email protected]/orga/subgroup/owner/repo.git" | ||
).projectPath, | ||
"orga/subgroup/owner/repo" | ||
); | ||
}); | ||
|
||
test("Get project path from GitLab CI", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } }, | ||
"https://gitlbab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectPath, | ||
"other-owner/other-repo" | ||
); | ||
}); | ||
|
||
test("Ignore CI_PROJECT_PATH if not on GitLab CI", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "travis" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } }, | ||
"https://gitlbab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectPath, | ||
"owner/repo" | ||
); | ||
}); | ||
|
||
test("Get project ID from GitLab CI", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_ID: "42" } }, | ||
"https://gitlbab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectId, | ||
"42" | ||
); | ||
}); | ||
|
||
test("Ignore CI_PROJECT_ID if not on GitLab CI", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "travis" }, env: { CI_PROJECT_ID: "42" } }, | ||
"https://gitlbab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectId, | ||
null | ||
); | ||
}); | ||
|
||
test("Uses project API URL with project path", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } }, | ||
"https://gitlab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectApiUrl, | ||
"https://api.gitlab.com/projects/other-owner%2Fother-repo" | ||
); | ||
}); | ||
|
||
test("Uses project API URL with project ID", (t) => { | ||
t.is( | ||
getProjectContext( | ||
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_ID: "42" } }, | ||
"https://gitlab.com", | ||
"https://api.gitlab.com", | ||
"https://gitlab.com/owner/repo.git" | ||
).projectApiUrl, | ||
"https://api.gitlab.com/projects/42" | ||
); | ||
}); |
This file was deleted.
Oops, something went wrong.