Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: auto-generate maintainer away issue #842

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/maintainer-absence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: maintainer-absence

on:
workflow_dispatch:
inputs:
startDate:
description: 'First day of maintainer absence [mm-dd-yyyy]'
required: true
endDate:
description: 'Last day of maintainer absence [mm-dd-yyyy]'
required: true
ldennington marked this conversation as resolved.
Show resolved Hide resolved

permissions:
issues: write

jobs:
create-issue:
name: create-issue
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const startDate = new Date('${{ github.event.inputs.startDate }}');
const endDate = new Date('${{ github.event.inputs.endDate }}');

if (startDate > endDate) {
throw 'Start date cannot be later than end date.';
}

// Calculate total days of absence
const differenceInDays = endDate.getTime() - startDate.getTime();
const lengthOfAbsence = differenceInDays/(1000 * 3600 * 24);

// Create issue
issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
// Use the briefer input date format in title (instead of JavaScript's full date string)
title: `Maintainer(s) will be away from ${{ github.event.inputs.startDate }} until ${{ github.event.inputs.endDate }}`,
body: `The ${context.repo.repo} maintainer(s) will be away for ${lengthOfAbsence} day${lengthOfAbsence > 1 ? 's' : ''} beginning on
${startDate.toDateString()} and ending on ${endDate.toDateString()}. During this time, the maintainer(s)
will not be actively monitoring PRs, discussions, etc. Please report any issues
requiring immediate attention to [@GitCredManager](https://twitter.com/GitCredManager) on Twitter.`
});

// Pin issue - we use GraphQL since there is no GitHub API available for this
const mutation = `mutation($issueId: ID!) {
pinIssue(input: { issueId: $issueId }) {
issue {
repository {
id
}
}
}
}`;
const variables = {
issueId: issue.data.node_id
}
const result = await github.graphql(mutation, variables)