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

ci: add design complete automation #7184

Merged
merged 4 commits into from
Jun 16, 2023
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
76 changes: 76 additions & 0 deletions .github/workflows/design-complete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# When the "design-complete" label is added to an issue:
# 1. Modifies the labels,
# 2. Updates the assignees and milestone, and
# 3. Generates a notification to the Calcite project manager(s)
#
# The secret is formatted like so: person1, person2, person3
#
# Note the script automatically adds the "@" character in to notify the project manager(s)
name: "Design complete"

on:
issues:
types: [labeled]

jobs:
design-complete:
if: github.event.label.name == 'design-complete'
permissions:
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
env:
managers: ${{secrets.CALCITE_MANAGERS}}
with:
script: |
const { managers } = process.env;
const { label } = context.payload;

if (label && label.name === "design-complete") {

// Add a "@" character to notify the user
const calcite_managers = managers.split(",").map(v => " @" + v.trim());

const issueProps = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
}

/* Modify labels */

// Remove "Design" label
await github.rest.issues.removeLabel({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API calls are pretty expressive, so one suggestion to remove some comments with duplicate info is to use an object for common props and spread into each call:

const commonProps = { 
  issue_number: context.issue.number,
  owner: context.repo.owner,
  repo: context.repo.repo
};

await github.rest.issues.removeLabel({
  name: "design",
  ...commonProps
});

await github.rest.issues.removeLabel({
  name: "1 - assigned",
  ...commonProps
});

...issueProps,
name: "design"
});

// Remove "1 - assigned" label
await github.rest.issues.removeLabel({
...issueProps,
name: "1 - assigned"
});

// Add labels
await github.rest.issues.addLabels({
...issueProps,
labels: ['0 - new', 'needs milestone']
})

/* Update issue */

// Clear assignees and milestone
await github.rest.issues.update({
...issueProps,
assignees: [],
milestone: null
});

// Add a comment to notify the project manager(s)
await github.rest.issues.createComment({
...issueProps,
body: `cc ${calcite_managers}`,
});

}