Skip to content

Commit

Permalink
Merge pull request #32605 from hashicorp/m-actions-labels
Browse files Browse the repository at this point in the history
Rework Labeling & Project Automation Workflows
  • Loading branch information
justinretzolk authored Jul 25, 2023
2 parents 0109317 + f7fccf4 commit 450453f
Show file tree
Hide file tree
Showing 21 changed files with 572 additions and 331 deletions.
78 changes: 78 additions & 0 deletions .ci/scripts/archive-on-milestone-closed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

PROJECT_NUMBER=196
PROJECT_ID="PVT_kwDOAAuecM4AF-7h"

main () {
ISSUES=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
issues(first: 10, after: $endCursor) {
edges {
node {
id
projectItems(includeArchived: false, first: 10) {
nodes {
id
project {
id
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.issues.edges[].node.projectItems.nodes[]' | jq --slurp '. | tojson')

PULLS=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
pullRequests(first: 10, after: $endCursor) {
edges {
node {
id
projectItems(includeArchived: false, first: 10) {
nodes {
id
project {
id
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.pullRequests.edges[].node.projectItems.nodes[]' | jq --slurp '. | tojson')

PROJECT_ITEMS=$(jq \
--null-input \
--arg project "$PROJECT_ID" \
--argjson issues "$ISSUES" \
--argjson pulls "$PULLS" \
'$issues, $pulls | fromjson | .[] | select(.project.id == $project).id')

for item in $PROJECT_ITEMS; do
echo "Archiving $item"
gh project item-archive "$PROJECT_NUMBER" --owner "hashicorp" --id "$item"
done
}

main
55 changes: 55 additions & 0 deletions .ci/scripts/unlabel-on-milestone-closed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

main () {
ISSUES=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
issues(first: 10, after: $endCursor, labels: ["prioritized"]) {
edges {
node {
url
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.issues.edges[].node' | jq --raw-output --slurp '[.[].url] | join(" ")')

PULLS=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
pullRequests(first: 10, after: $endCursor, labels: ["prioritized"]) {
edges {
node {
url
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.pullRequests.edges[].node' | jq --raw-output --slurp '.[] | .url')

# gh issues allows passing multiple URLs at once
gh issue edit $ISSUES --remove-label bug

# gh pr does not allow passing multiple URLs at once
for item in $PULLS; do
gh pr edit "$item" --remove-label bug
done
}

main
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/00_bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Report a Bug"
description: "Choose this option to let us know about an unexpected error, a crash, or otherwise incorrect behavior."
title: "[Bug]: "
labels: ["bug", "needs-triage"]
labels: ["bug"]
body:
- type: markdown
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/01_documentation.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Report a Documentation Error"
description: "Choose this option if you've found an error in the provider documentation or contribution guides."
title: "[Docs]: "
labels: ["documentation", "needs-triage"]
labels: ["documentation"]
body:
- type: markdown
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/02_enhancement.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Request an Enhancement"
description: "Choose this option when you would like to request an enhancement to an existing resource, data source, or the provider itself."
title: "[Enhancement]: "
labels: ["enhancement", "needs-triage"]
labels: ["enhancement"]
body:
- type: markdown
attributes:
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/03_new_resource.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "Request a New Resource, Data Source, or AWS Service"
description: "Choose this option to request an entirely new resource, data source, or AWS service be added to the provider."
title: "[New]: "
labels: ["needs-triage"]
body:
- type: markdown
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/04_repository.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Repository/Meta"
description: Choose this option when the issue has to do with the repository itself, including GitHub Actions, labels, workflows, etc.
title: "[Repo]: "
labels: ["repository", "needs-triage"]
labels: ["repository"]
body:
- type: markdown
attributes:
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/05_other.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: "Other"
description: "Choose this option if your issue does not fit the description of the others."
labels: ["needs-triage"]
body:
- type: markdown
attributes:
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/autoremove_labels.yml

This file was deleted.

50 changes: 0 additions & 50 deletions .github/workflows/community-comment.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/issue-comment-created.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/issue_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Process issue_comment Events'

on:
issue_comment:
types: [created]

jobs:
community_check:
name: 'Community Check'
uses: ./.github/workflows/community-check.yml
secrets: inherit
with:
username: ${{ github.event.comment.user.login }}

automation_labeler:
name: 'Automation Labeler'
needs: community_check
runs-on: ubuntu-latest
env:
# This is a ternary that sets the variable to the assigned user's login on assigned events,
# and otherwise sets it to the username of the pull request's author. For more information:
# https://docs.github.com/en/actions/learn-github-actions/expressions#example
#
# issue_comment events are triggered by comments on issues and pull requests. Checking the
# value of github.event.issue.pull_request tells us whether the issue is an issue or is
# actually a pull request, allowing us to dynamically set the gh subcommand:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only
COMMAND: ${{ github.event.issue.pull_request && 'pr' || 'issue' }}
GH_TOKEN: ${{ github.token }}
steps:
- name: 'Remove stale and waiting-response on non-maintainer comment'
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only
run: gh ${{ env.COMMAND }} edit ${{ github.event.issue.html_url }} --remove-label stale,waiting-response
Loading

0 comments on commit 450453f

Please sign in to comment.