|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +/** |
| 4 | + * @param {Object} params |
| 5 | + * @param {import("@actions/core")} params.core |
| 6 | + * @param {ReturnType<import("@actions/github").getOctokit>} params.github |
| 7 | + * @param {import("@actions/github").context} params.context |
| 8 | + */ |
| 9 | +module.exports = async ({ core, context, github }) => { |
| 10 | + try { |
| 11 | + const owner = context.repo.owner; |
| 12 | + const repo = context.repo.repo; |
| 13 | + const issueNumber = context.issue.number; |
| 14 | + |
| 15 | + const issue = await github.rest.issues.get({ |
| 16 | + owner, |
| 17 | + repo, |
| 18 | + issue_number: issueNumber, |
| 19 | + }); |
| 20 | + |
| 21 | + const repositoryMap = { |
| 22 | + 'mui-x': 'x', |
| 23 | + 'material-ui': 'core', |
| 24 | + 'base-ui': 'base', |
| 25 | + 'pigment-css': 'pigment', |
| 26 | + 'mui-toolpad': 'toolpad', |
| 27 | + }; |
| 28 | + |
| 29 | + const commentLines = [ |
| 30 | + `**This issue has been closed.** If you have a similar problem but not exactly the same, please open a [new issue](https://github.com/mui/${repo}/issues/new/choose).`, |
| 31 | + 'Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.', |
| 32 | + ]; |
| 33 | + |
| 34 | + const userPermission = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 35 | + owner, |
| 36 | + repo, |
| 37 | + username: issue.data.user.login, |
| 38 | + }); |
| 39 | + |
| 40 | + core.debug(`>>> Author permission level: ${userPermission.data.permission}`); |
| 41 | + |
| 42 | + // Only ask for feedback if the user is not an admin or has at least write access (from a team membership) |
| 43 | + if (!['admin', 'write'].includes(userPermission.data.permission)) { |
| 44 | + commentLines.push('> [!NOTE]'); |
| 45 | + commentLines.push( |
| 46 | + `> We value your feedback @${issue.data.user.login}! How was your experience with our support team?`, |
| 47 | + ); |
| 48 | + commentLines.push( |
| 49 | + `> If you could spare a moment, we'd love to hear your thoughts in this brief [Support Satisfaction survey](https://tally.so/r/w4r5Mk?issue=${issueNumber}&productId=${repositoryMap[repo]}). Your insights help us improve!`, |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + const body = commentLines.join('\n'); |
| 54 | + core.debug(`>>> Prepared comment body: ${body}`); |
| 55 | + |
| 56 | + await github.rest.issues.createComment({ |
| 57 | + owner, |
| 58 | + repo, |
| 59 | + issue_number: issueNumber, |
| 60 | + body, |
| 61 | + }); |
| 62 | + |
| 63 | + const labelName = 'status: waiting for maintainer'; |
| 64 | + core.debug(`>>> Removing label: ${labelName}`); |
| 65 | + |
| 66 | + await github.rest.issues.removeLabel({ |
| 67 | + owner, |
| 68 | + repo, |
| 69 | + issue_number: issueNumber, |
| 70 | + name: labelName, |
| 71 | + }); |
| 72 | + } catch (error) { |
| 73 | + core.setFailed(error.message); |
| 74 | + } |
| 75 | +}; |
0 commit comments