Skip to content

Commit 19fd88a

Browse files
committed
Added test workflows
1 parent 72c2acc commit 19fd88a

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow manages issue assignments and related label changes:
2+
# 1. When someone is assigned to an issue:
3+
# - Removes "stat:awaiting-triage" label
4+
# - Adds "stat:Investigating" label
5+
# 2. When all assignees are removed from an issue:
6+
# - Adds "stat:awaiting-triage" label
7+
# - Removes "stat:Investigating" label
8+
# 3. When "stat:Investigating" label is added:
9+
# - Automatically assigns the issue to the person who added the label
10+
11+
name: Handle Issue Assignment and Labels
12+
13+
on:
14+
issues:
15+
types: [assigned, unassigned, labeled]
16+
17+
env:
18+
AWAITING-TRIAGE_LABEL: stat:awaiting triage
19+
INVESTIGATING_LABEL: stat:Investigating
20+
21+
jobs:
22+
handle_assignment:
23+
name: Handle Issue Assignment Changes
24+
if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }}
25+
runs-on: ubuntu-latest
26+
permissions:
27+
issues: write
28+
29+
steps:
30+
- name: Handle Assignment Changes
31+
run: |
32+
if [[ "${{ github.event.action }}" == "assigned" ]]; then
33+
# Someone was assigned - remove awaiting-triage, add investigating
34+
echo "ADD=${{ env.INVESTIGATING_LABEL }}" >> $GITHUB_ENV
35+
echo "REMOVE=${{ env.AWAITING-TRIAGE_LABEL }}" >> $GITHUB_ENV
36+
elif [[ "${{ github.event.action }}" == "unassigned" ]]; then
37+
# Check if there are any remaining assignees
38+
ASSIGNEES=$(echo '${{ toJson(github.event.issue.assignees) }}' | jq length)
39+
if [[ "$ASSIGNEES" == "0" ]]; then
40+
# No assignees left - add awaiting-triage, remove investigating
41+
echo "ADD=${{ env.AWAITING-TRIAGE_LABEL }}" >> $GITHUB_ENV
42+
echo "REMOVE=${{ env.INVESTIGATING_LABEL }}" >> $GITHUB_ENV
43+
fi
44+
fi
45+
46+
- name: Update Labels
47+
if: env.ADD != '' || env.REMOVE != ''
48+
run: gh issue edit "$NUMBER" --add-label "$ADD" --remove-label "$REMOVE"
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
GH_REPO: ${{ github.repository }}
52+
NUMBER: ${{ github.event.issue.number }}
53+
54+
handle_investigating_label:
55+
name: Handle Investigating Label Addition
56+
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'stat:Investigating' && !github.event.issue.pull_request && github.event.issue.state == 'open' }}
57+
runs-on: ubuntu-latest
58+
permissions:
59+
issues: write
60+
61+
steps:
62+
- name: Assign Issue to Label Creator
63+
run: |
64+
# Assign the issue to the person who added the label
65+
gh issue edit "$NUMBER" --add-assignee "$ACTOR"
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
GH_REPO: ${{ github.repository }}
69+
NUMBER: ${{ github.event.issue.number }}
70+
ACTOR: ${{ github.actor }}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This workflow will update issues with proper "conversation related" labels. This mean that stat:awaiting-repsonse label will be present after Unity account made comments and stat:reply-needed will be present when user made latest comment
2+
3+
name: Update conversation labels of the issue
4+
5+
# Trigger for the workflow
6+
# This trigger will populate the github.event object
7+
# Details on properties are here: https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=created#issue_comment
8+
on:
9+
issue_comment:
10+
types: [created]
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.issue.number }}
14+
cancel-in-progress: true
15+
16+
# Define labels here
17+
env:
18+
AWAITING_RESPONSE: stat:awaiting-response
19+
REPLY_NEEDED: stat:reply-needed
20+
21+
jobs:
22+
conversation_labels:
23+
name: Calculate and update conversation labels of the issue
24+
if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }}
25+
runs-on: ubuntu-latest
26+
permissions:
27+
issues: write
28+
29+
steps:
30+
- name: Calculate labels
31+
run: |
32+
33+
if [[ "${{ github.event.comment.author_association }}" == "MEMBER" ]]; then
34+
# Unity member commented - add awaiting-response, remove reply-needed
35+
echo "ADD=${{ env.AWAITING_RESPONSE }}" >> $GITHUB_ENV
36+
echo "REMOVE=${{ env.REPLY_NEEDED }}" >> $GITHUB_ENV
37+
else
38+
# Non-Unity member commented - add reply-needed, remove awaiting-response
39+
echo "ADD=${{ env.REPLY_NEEDED }}" >> $GITHUB_ENV
40+
echo "REMOVE=${{ env.AWAITING_RESPONSE }}" >> $GITHUB_ENV
41+
fi
42+
43+
- name: Update labels
44+
# This runs a command using the github cli: https://cli.github.com/manual/gh_issue_edit
45+
# If $ADD is set, it will add the label, otherwise it will remove the label
46+
# There is no need to check if $ADD or $REMOVE is set, as the command will ignore it if it is empty
47+
run: gh issue edit "$NUMBER" --add-label "$ADD" --remove-label "$REMOVE"
48+
env:
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
GH_REPO: ${{ github.repository }}
51+
NUMBER: ${{ github.event.issue.number }}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Mark Stale Issues
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *' # Runs daily at midnight
7+
8+
env:
9+
AWAITING-RESPONSE_LABEL: stat:awaiting-response
10+
STALE_LABEL: stale
11+
DAYS_BEFORE_STALE: 60 # 2 months
12+
13+
jobs:
14+
mark_stale:
15+
name: Check and Mark Stale Issues
16+
if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }}
17+
runs-on: ubuntu-latest
18+
permissions:
19+
issues: write
20+
21+
steps:
22+
- name: Get Issues with Awaiting Response
23+
id: get_issues
24+
run: |
25+
# Get all open issues with awaiting-response label
26+
ISSUES=$(gh issue list --label "${{ env.AWAITING-RESPONSE_LABEL }}" --json number,labels,updatedAt --jq '.[]')
27+
28+
echo "ISSUES=$ISSUES" >> $GITHUB_ENV
29+
30+
- name: Process Issues
31+
run: |
32+
current_time=$(date +%s)
33+
34+
echo "$ISSUES" | while read -r issue; do
35+
# Extract issue details
36+
number=$(echo "$issue" | jq -r .number)
37+
updated_at=$(echo "$issue" | jq -r .updatedAt)
38+
has_stale=$(echo "$issue" | jq -r '.labels[].name | select(. == "stale")' || echo "")
39+
40+
# Convert updated_at to timestamp
41+
updated_time=$(date -d "$updated_at" +%s)
42+
43+
# Calculate days difference
44+
days_diff=$(( (current_time - updated_time) / 86400 ))
45+
46+
# Check if issue should be marked stale
47+
if [[ $days_diff -ge ${{ env.DAYS_BEFORE_STALE }} && -z "$has_stale" ]]; then
48+
echo "Marking issue #$number as stale"
49+
gh issue edit "$number" --add-label "${{ env.STALE_LABEL }}" \
50+
--body-file <(
51+
echo "This issue has been automatically marked as stale because it has been awaiting response for over 2 months without any activity."
52+
echo ""
53+
echo "Please update the issue with any new information or it may be closed in the future."
54+
)
55+
fi
56+
done
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
GH_REPO: ${{ github.repository }}
60+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will remove almost all labels from closed issues beside ones that could be relevant for future tracking like: "port:", "type:", "priority:" and "regression"
2+
3+
name: Remove labels when issue is closed
4+
5+
on:
6+
issues:
7+
types: [closed] # We want it to run on closed issues
8+
9+
jobs:
10+
remove_labels:
11+
name: Calculate and remove issue labels
12+
if: ${{ !github.event.issue.pull_request }} # This is needed to distinguish from PRs (which we don't want to affect)
13+
runs-on: ubuntu-latest
14+
permissions:
15+
issues: write
16+
17+
steps:
18+
- name: Find labels to remove
19+
id: data
20+
run: |
21+
# Convert labels to array and filter out type: labels
22+
LABELS_TO_REMOVE=($(echo "$EXISTING_LABELS" | jq -r '.[] | select(startswith("type:") or startswith("port:") or startswith("priority:") or . == "regression" | not)'))
23+
24+
# Only proceed if we have labels to remove
25+
if [ ${#LABELS_TO_REMOVE[@]} -gt 0 ]; then
26+
echo "REMOVE_LABELS=$(IFS=,; echo "${LABELS_TO_REMOVE[*]}")" >> $GITHUB_ENV
27+
echo "HAS_LABELS=true" >> $GITHUB_ENV
28+
else
29+
echo "HAS_LABELS=false" >> $GITHUB_ENV
30+
fi
31+
env:
32+
EXISTING_LABELS: ${{ toJson(github.event.issue.labels.*.name) }}
33+
34+
- name: Remove labels
35+
if: env.HAS_LABELS == 'true'
36+
run: gh issue edit "$NUMBER" --remove-label "$REMOVE_LABELS"
37+
env:
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
GH_REPO: ${{ github.repository }}
40+
NUMBER: ${{ github.event.issue.number }}

0 commit comments

Comments
 (0)