-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infra] Issue title cleanup script and keywords improvement (#255)
Signed-off-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com> Co-authored-by: Jose C Quintas Jr <juniorquintas@gmail.com>
- Loading branch information
1 parent
8eb4a0a
commit bcbdbf7
Showing
3 changed files
with
76 additions
and
2 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 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// @ts-check | ||
const regexes = { | ||
// covers 'dataGrid' in all variants, as well as with suffixes (-pro/-premium/etc) | ||
dataGrid: /\s*\[\s*(data[\s-]?grid[-\sA-Za-z]*)\s*]/gi, | ||
// covers 'charts' in all variants, as well as with prefixes (PieChart, LineChart, etc) | ||
charts: /\s*\[\s*([-\sA-Za-z]*charts?)\s*]/gi, | ||
// covers 'pickers' in all variants, as well as with prefixes (DatePicker, time-picker, etc) | ||
pickers: /\s*\[\s*([-\sA-Za-z]*pickers?)\s*]/gi, | ||
// covers 'treeView' in all variants | ||
treeView: /\s*\[\s*([-\sA-Za-z]*tree\s?(view|item))\s*]/gi, | ||
}; | ||
|
||
const replacements = { | ||
dataGrid: 'data grid', | ||
charts: 'charts', | ||
pickers: 'pickers', | ||
treeView: 'tree view', | ||
}; | ||
|
||
/** | ||
* @param {Object} params | ||
* @param {import("@actions/core")} params.core | ||
* @param {ReturnType<import("@actions/github").getOctokit>} params.github | ||
* @param {import("@actions/github").context} params.context | ||
*/ | ||
module.exports = async ({ core, context, github }) => { | ||
try { | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const issueNumber = context.issue.number; | ||
|
||
const issue = await github.rest.issues.get({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
}); | ||
|
||
core.info(`>>> Original title: ${issue.data.title}`); | ||
|
||
let result = issue.data.title; | ||
|
||
// Replace each capture group using its specific regex | ||
for (const [key, regex] of Object.entries(regexes)) { | ||
const replacement = replacements[key]; // Get the replacement for the current group | ||
result = result.replace(regex, `[${replacement}]`); // Replace all matches for this group | ||
} | ||
|
||
core.info(`>>> Updated title: ${result}`); | ||
|
||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
title: result, | ||
}); | ||
} catch (error) { | ||
core.error(`>>> Workflow failed with: ${error.message}`); | ||
core.setFailed(error.message); | ||
} | ||
}; |