-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54857b1
commit 77cb008
Showing
2 changed files
with
120 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { execSync } from 'child_process' | ||
import fetch from 'node-fetch' | ||
|
||
function getApiInfos() { | ||
const { GITLAB_API_PRIVATE_TOKEN: token, GITLAB_API_ENDPOINT: api } = | ||
process.env | ||
|
||
if (!token) { | ||
throw new Error('Gitlab TOKEN is not defined') | ||
} | ||
|
||
if (!api) { | ||
throw new Error('Gitlab API is not defined') | ||
} | ||
|
||
return { token, api } | ||
} | ||
|
||
function getProjectPath() { | ||
const projectRemote = execSync('git remote get-url origin').toString() | ||
const projectPath = encodeURIComponent( | ||
projectRemote.trim().replace(/^git@git\.epic\.net:(.*)\.git+$/, '$1') | ||
) | ||
|
||
return projectPath | ||
} | ||
|
||
async function getIssues() { | ||
try { | ||
// ? manage pagination? | ||
const page = 1 | ||
const { api, token } = getApiInfos() | ||
const projectPath = getProjectPath() | ||
const url = `${api}/projects/${projectPath}/issues` | ||
const res = await fetch(`${url}?state=opened&per_page=5&page=${page}`, { | ||
headers: { | ||
'PRIVATE-TOKEN': token, | ||
}, | ||
}) | ||
|
||
if (!res.ok) { | ||
console.error( | ||
`Error fetching issues [${url}]`, | ||
res.status, | ||
res.statusText | ||
) | ||
|
||
return [] | ||
} | ||
|
||
const data = await res.json() | ||
const issues = data.map(issue => ({ | ||
name: `#${issue.iid} - ${issue.title}`, | ||
value: issue.iid, | ||
})) | ||
|
||
return issues | ||
} catch (error) { | ||
console.error(error.message) | ||
|
||
return [] | ||
} | ||
} | ||
|
||
export { getIssues } |
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