|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +function extractInputSection(lines, title) { |
| 4 | + const index = lines.findIndex((line) => line.startsWith('###') && line.includes(title)); |
| 5 | + if (index === -1) { |
| 6 | + return ''; |
| 7 | + } |
| 8 | + return lines.splice(index, 4)[2].trim(); |
| 9 | +} |
| 10 | + |
| 11 | +const productMap = { |
| 12 | + 'Data Grid': 'data grid', |
| 13 | + 'Date and Time Pickers': 'pickers', |
| 14 | + Charts: 'charts', |
| 15 | + 'Tree View': 'tree view', |
| 16 | +}; |
| 17 | + |
| 18 | +/** |
| 19 | + * @param {Object} params |
| 20 | + * @param {import("@actions/core")} params.core |
| 21 | + * @param {ReturnType<import("@actions/github").getOctokit>} params.github |
| 22 | + * @param {import("@actions/github").context} params.context |
| 23 | + */ |
| 24 | +module.exports = async ({ core, context, github }) => { |
| 25 | + try { |
| 26 | + const owner = context.repo.owner; |
| 27 | + const repo = context.repo.repo; |
| 28 | + const issueNumber = context.issue.number; |
| 29 | + |
| 30 | + const issue = await github.rest.issues.get({ |
| 31 | + owner, |
| 32 | + repo, |
| 33 | + issue_number: issueNumber, |
| 34 | + }); |
| 35 | + |
| 36 | + const lines = issue.data.body.split('\n'); |
| 37 | + |
| 38 | + // this is here to remove this section from the issue body |
| 39 | + extractInputSection(lines, 'Latest version'); |
| 40 | + |
| 41 | + const searchKeywords = extractInputSection(lines, 'Search keywords'); |
| 42 | + const products = extractInputSection(lines, 'Affected products'); |
| 43 | + |
| 44 | + // get the order id and set it as an output for the support label step |
| 45 | + let orderID = extractInputSection(lines, 'Order ID or Support key'); |
| 46 | + if (orderID === '_No response_') { |
| 47 | + orderID = ''; |
| 48 | + } |
| 49 | + |
| 50 | + // set the order id as an output (to be consumed by following workflows) |
| 51 | + core.setOutput('ORDER_ID', orderID); |
| 52 | + |
| 53 | + // log all the values |
| 54 | + core.info(`>>> Search Keywords: ${searchKeywords}`); |
| 55 | + core.info(`>>> Order ID: ${orderID}`); |
| 56 | + core.info(`>>> Affected Products: ${products}`); |
| 57 | + |
| 58 | + lines.push(''); |
| 59 | + lines.push(`**Search keywords**: ${searchKeywords}`); |
| 60 | + if (orderID !== '') { |
| 61 | + lines.push(`**Order ID**: ${orderID}`); |
| 62 | + } |
| 63 | + |
| 64 | + const body = lines.join('\n'); |
| 65 | + core.info(`>>> Cleansed issue body: ${body}`); |
| 66 | + |
| 67 | + const labels = issue.data.labels.map((label) => label.name); |
| 68 | + |
| 69 | + if (products !== '') { |
| 70 | + products.split(',').forEach((product) => { |
| 71 | + if (productMap[product.trim()]) { |
| 72 | + labels.push(`component: ${productMap[product.trim()]}`); |
| 73 | + } |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + core.info(`>>> Labels: ${labels.join(',')}`); |
| 78 | + |
| 79 | + await github.rest.issues.update({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + issue_number: context.issue.number, |
| 83 | + body, |
| 84 | + labels, |
| 85 | + }); |
| 86 | + } catch (error) { |
| 87 | + core.error(`>>> Workflow failed with: ${error.message}`); |
| 88 | + core.setFailed(error.message); |
| 89 | + } |
| 90 | +}; |
0 commit comments