diff --git a/.github/workflows/issues_body-cleanup.yml b/.github/workflows/issues_body-cleanup.yml index fde0890..058b057 100644 --- a/.github/workflows/issues_body-cleanup.yml +++ b/.github/workflows/issues_body-cleanup.yml @@ -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 diff --git a/.github/workflows/scripts/issues/bodyCleanup.js b/.github/workflows/scripts/issues/bodyCleanup.js index ae1bbc9..b0474be 100644 --- a/.github/workflows/scripts/issues/bodyCleanup.js +++ b/.github/workflows/scripts/issues/bodyCleanup.js @@ -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}`); } @@ -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, }); diff --git a/.github/workflows/scripts/issues/titleCleanup.js b/.github/workflows/scripts/issues/titleCleanup.js new file mode 100644 index 0000000..b36d80d --- /dev/null +++ b/.github/workflows/scripts/issues/titleCleanup.js @@ -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} 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); + } +};