forked from RampNetwork/clicop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate logic from ClickUp to Jira #PLTM-233 (RampNetwork#12)
* chore: remove ClickUp logic * feat: logic for Jira issues * refactor: simplify task reference parsing * fix: typo * feat: ignore duplicates and return tasks in alphabetical order * fix: promise not awaited * fix: invalid Jira request auth and response parsing * feat: search just the commit title for issue references * docs: change package.json description * docs: update README.md * fix: remove references to tickets in description * cleanup: remove redundant join operation Co-authored-by: Artur Kozak <[email protected]> * feat: do not sort tasks alphabetically * feat: match issue references only in the end of the title * test: adjust tests * chore: add information about placing issue references at the end of title * feat: use Github variable for token's user --------- Co-authored-by: Artur Kozak <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
120 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 |
---|---|---|
|
@@ -2,14 +2,13 @@ | |
![CliCop logo](clicop.png) | ||
|
||
|
||
CliCop is an Github Actions action that enforces pinning ClickUp ticket id reference in a PR.\ | ||
I will fail if there is no task id in PR title or body.\ | ||
It does not yet check if the task really exists in ClickUp.\ | ||
CliCop is an Github Actions action that enforces pinning ticket id reference in a PR.\ | ||
It will fail if there is no task id in PR title.\ | ||
It utilizes [DangerJS](https://danger.systems/js/) to perform the check. | ||
|
||
## Inputs | ||
github_token - Github authentification token. | ||
clickup_token - ClickUp authentification token. | ||
jira_token - Jira authentification token. | ||
|
||
## Testing | ||
The action conitains some unit tests. To run them: | ||
|
@@ -42,5 +41,5 @@ jobs: | |
- uses: RampNetwork/github-actions/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} # this is passed automatically https://docs.github.com/en/actions/security-guides/automatic-token-authentication | ||
clickup_token: ${{ secrets.CLICKUP_TOKEN }} | ||
jira_token: ${{ secrets.JIRA_TOKEN }} | ||
``` |
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 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 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 |
---|---|---|
@@ -1,27 +1,23 @@ | ||
/** | ||
* Acceptable formats: | ||
* - #20jt35r | ||
* - #CORE-123 | ||
*/ | ||
const getTasks = (source) => { | ||
const ticketRefRegex = /(?<=\s|^)#(([A-Z]{2,10}-\d+)|(\w{7,10}))/g; | ||
const ticketIdRegex = /#(?<taskId>([A-Z]{2,10}-\d+)|(\w{7,10}))/; | ||
const customTicketIdRegex = /#[A-Z]{2,10}-\d+/; | ||
const ids = | ||
source.match(ticketRefRegex)?.map(v => ({ | ||
...v.match(ticketIdRegex).groups, | ||
isCustom: customTicketIdRegex.test(v), | ||
})) || []; | ||
// Matches the prefix of the string containg only issue references delimited with whitespaces | ||
const prefixWithRefsRegex = /((\s+|^)#[A-Z]{2,10}-\d+)+$/; | ||
const [prefix] = source.match(prefixWithRefsRegex) || ['']; | ||
// Picks individual issue references from the string | ||
const taskRefRegex = /(?<=(\s|^)#)[A-Z]{2,10}-\d+/g; | ||
const refs = prefix.match(taskRefRegex) || []; | ||
const uniqueRefs = new Set(refs); | ||
|
||
return Object.values( | ||
ids.reduce( | ||
(tasks, task) => ({ | ||
...tasks, | ||
[task.taskId]: task, | ||
}), | ||
{} | ||
) | ||
); | ||
}; | ||
let tasks = []; | ||
for (const ref of uniqueRefs) { | ||
tasks.push({ | ||
taskId: ref, | ||
}); | ||
} | ||
return tasks; | ||
}; | ||
|
||
module.exports = getTasks; |
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 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