Skip to content

Commit

Permalink
[infra] Issue title cleanup script and keywords improvement (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com>
Co-authored-by: Jose C Quintas Jr <juniorquintas@gmail.com>
  • Loading branch information
michelengelen and JCQuintas authored Dec 13, 2024
1 parent 8eb4a0a commit bcbdbf7
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/issues_body-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ jobs:
# Check this repository out, otherwise the script won't be available,
# as it otherwise checks out the repository where the workflow caller is located
repository: mui/mui-public
- name: Clean issue title
# for now this only works (makes sense) for mui-x
if: github.event.repository.name == 'mui-x'
id: titleCleanup
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const script = require('./.github/workflows/scripts/issues/titleCleanup.js')
await script({core, github, context})
- name: Clean issue body
id: cleanup
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/scripts/issues/bodyCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ module.exports = async ({ core, context, github }) => {
core.info(`>>> Order ID: ${orderID}`);
core.info(`>>> Affected Products: ${products}`);

lines.push('');
lines.push(`**Search keywords**: ${searchKeywords}`);
if (searchKeywords !== '') {
lines.push('');
lines.push(`**Search keywords**: ${searchKeywords}`);
}

if (orderID !== '') {
lines.push('');
lines.push(`**Order ID**: ${orderID}`);
}

Expand All @@ -80,6 +84,7 @@ module.exports = async ({ core, context, github }) => {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
title: issue.data.title,
body,
labels,
});
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/scripts/issues/titleCleanup.js
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);
}
};

0 comments on commit bcbdbf7

Please sign in to comment.