1+ name : maintainer-absence
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ startDate :
7+ description : ' First day of maintainer absence [mm-dd-yyyy]'
8+ required : true
9+ endDate :
10+ description : ' Last day of maintainer absence [mm-dd-yyyy]'
11+ required : true
12+
13+ permissions :
14+ issues : write
15+
16+ jobs :
17+ create-issue :
18+ name : create-issue
19+ runs-on : ubuntu-latest
20+ steps :
21+ - uses : actions/github-script@v6
22+ with :
23+ script : |
24+ const startDate = new Date('${{ github.event.inputs.startDate }}');
25+ const endDate = new Date('${{ github.event.inputs.endDate }}');
26+
27+ if (startDate > endDate) {
28+ throw 'Start date cannot be later than end date.';
29+ }
30+
31+ // Calculate total days of absence
32+ const differenceInDays = endDate.getTime() - startDate.getTime();
33+ const lengthOfAbsence = differenceInDays/(1000 * 3600 * 24);
34+
35+ // Create issue
36+ issue = await github.rest.issues.create({
37+ owner: context.repo.owner,
38+ repo: context.repo.repo,
39+ // Use the briefer input date format in title (instead of JavaScript's full date string)
40+ title: `Maintainer(s) will be away from ${{ github.event.inputs.startDate }} until ${{ github.event.inputs.endDate }}`,
41+ body: `The ${context.repo.repo} maintainer(s) will be away for ${lengthOfAbsence} day${lengthOfAbsence > 1 ? 's' : ''} beginning on
42+ ${startDate.toDateString()} and ending on ${endDate.toDateString()}. During this time, the maintainer(s)
43+ will not be actively monitoring PRs, discussions, etc. Please report any issues
44+ requiring immediate attention to [@GitCredManager](https://twitter.com/GitCredManager) on Twitter.`
45+ });
46+
47+ // Pin issue - we use GraphQL since there is no GitHub API available for this
48+ const mutation = `mutation($issueId: ID!) {
49+ pinIssue(input: { issueId: $issueId }) {
50+ issue {
51+ repository {
52+ id
53+ }
54+ }
55+ }
56+ }`;
57+ const variables = {
58+ issueId: issue.data.node_id
59+ }
60+ const result = await github.graphql(mutation, variables)
0 commit comments