Skip to content

Commit 04275a9

Browse files
michelengelenJanpotJCQuintasoliviertassinari
authored
[infra] Create reusable workflows (#178)
Signed-off-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com> Co-authored-by: MUI bot <2109932+Janpot@users.noreply.github.com> Co-authored-by: Jose C Quintas Jr <juniorquintas@gmail.com> Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
1 parent 88ff73a commit 04275a9

File tree

4 files changed

+295
-9
lines changed

4 files changed

+295
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Add closing message to issue
2+
3+
on:
4+
issues:
5+
types:
6+
- closed
7+
workflow_call:
8+
9+
permissions: {}
10+
11+
jobs:
12+
add-comment:
13+
runs-on: ubuntu-latest
14+
name: Check author permission and add closing message
15+
permissions:
16+
issues: write
17+
steps:
18+
- name: Check out public repo
19+
uses: actions/checkout@v3
20+
with:
21+
# Check this repository out, otherwise the script won't be available,
22+
# as it checks out the repository where the workflow caller is located
23+
repository: mui/mui-public
24+
- name: Add closing message
25+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
26+
with:
27+
script: |
28+
const script = require('./.github/workflows/scripts/addClosingMessage.js')
29+
await script({core, github, context})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
};

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"prettier:all": "prettier --write . --ignore-path .eslintignore"
1010
},
1111
"devDependencies": {
12+
"@actions/core": "^1.10.1",
13+
"@actions/github": "^6.0.0",
1214
"@mui/monorepo": "https://github.com/mui/material-ui.git#master",
1315
"@typescript-eslint/eslint-plugin": "7.12.0",
1416
"@typescript-eslint/parser": "7.12.0",

0 commit comments

Comments
 (0)