Skip to content

Commit 599fa57

Browse files
authored
Merge pull request #28 from MisRob/issue-header-action
Improve action that manages issue headers
2 parents e4eac14 + 8d9d453 commit 599fa57

File tree

9 files changed

+515
-94
lines changed

9 files changed

+515
-94
lines changed

.github/ISSUE_TEMPLATE/bug_issue.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ about: Report a bug to help us improve
44
title: "[Brief description]"
55
---
66

7-
<!-- DO NOT REMOVE THE HEADER -->
8-
<!---HEADER START-->
9-
10-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
11-
12-
**This issue is not open for contribution. Visit <a href="https://learningequality.org/contributing-to-our-open-code-base/" target="_blank">Contributing guidelines</a>** to learn about the contributing process and how to find suitable issues.
13-
14-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
15-
16-
<!---HEADER END-->
17-
187
<!--
198
Instructions:
209
* Fill out the sections below, replace …'s with information about your issue

.github/ISSUE_TEMPLATE/enhancement_issue.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ Instructions:
1414
1515
-->
1616

17-
<!-- DO NOT REMOVE THE HEADER -->
18-
<!---HEADER START-->
19-
20-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
21-
22-
**This issue is not open for contribution. Visit <a href="https://learningequality.org/contributing-to-our-open-code-base/" target="_blank">Contributing guidelines</a>** to learn about the contributing process and how to find suitable issues.
23-
24-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
25-
26-
<!---HEADER END-->
27-
2817
## Desired behavior
2918
<!-- Briefly describe the behavior you would like to see -->
3019

.github/ISSUE_TEMPLATE/epic_issue.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ assignees: ''
77

88
---
99

10-
<!-- DO NOT REMOVE THE HEADER -->
11-
<!---HEADER START-->
12-
13-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
14-
15-
**This issue is not open for contribution. Visit <a href="https://learningequality.org/contributing-to-our-open-code-base/" target="_blank">Contributing guidelines</a>** to learn about the contributing process and how to find suitable issues.
16-
17-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
18-
19-
<!---HEADER END-->
20-
2110
_[General guidance: When drafting a feature project, the goal is to create a reference for project scope and context. Write for our core product team. The issue should not be overly technical, and should be be comprehensible and a useful reference to devs, designers, and QA team, to build a shared source of understanding. Anyone at LE should be able to read this and more or less understand the project. If there is relevant information or context that is for the internal team only, please add that in a notion page and link it, rather than adding directly to these issues.]_
2211

2312
## Overview

.github/ISSUE_TEMPLATE/other_issue.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,4 @@ name: Other issue
33
about: For issues that don't fit any other category
44
---
55

6-
<!-- DO NOT REMOVE THE HEADER -->
7-
<!---HEADER START-->
8-
9-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
10-
11-
**This issue is not open for contribution. Visit <a href="https://learningequality.org/contributing-to-our-open-code-base/" target="_blank">Contributing guidelines</a>** to learn about the contributing process and how to find suitable issues.
12-
13-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
14-
15-
<!---HEADER END-->
16-
176
## Description

.github/ISSUE_TEMPLATE/product_issue.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ assignees: ''
55

66
---
77

8-
<!-- DO NOT REMOVE THE HEADER -->
9-
<!---HEADER START-->
10-
11-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
12-
13-
**This issue is not open for contribution. Visit <a href="https://learningequality.org/contributing-to-our-open-code-base/" target="_blank">Contributing guidelines</a>** to learn about the contributing process and how to find suitable issues.
14-
15-
<img height="20px" src="https://i.imgur.com/c7hUeb5.jpeg">
16-
17-
<!---HEADER END-->
18-
19-
208
_[General guidance: Product issues should describe the feature, but are not actually technically specced for dev work.]_
219

2210
## Overview
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Manage issue header
2+
3+
on:
4+
issues:
5+
types: [opened, reopened, labeled, unlabeled]
6+
7+
jobs:
8+
call-workflow:
9+
name: Call shared workflow
10+
uses: learningequality/.github/.github/workflows/manage-issue-header.yml@main
11+
secrets:
12+
LE_BOT_APP_ID: ${{ secrets.LE_BOT_APP_ID }}
13+
LE_BOT_PRIVATE_KEY: ${{ secrets.LE_BOT_PRIVATE_KEY }}
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
name: Manage issue header
22

33
on:
4-
issues:
5-
types: [labeled, unlabeled]
6-
workflow_call:
7-
secrets:
8-
LE_BOT_APP_ID:
9-
description: "GitHub App ID for authentication"
10-
required: true
11-
LE_BOT_PRIVATE_KEY:
12-
description: "GitHub App Private Key for authentication"
13-
required: true
4+
workflow_call:
5+
secrets:
6+
LE_BOT_APP_ID:
7+
description: "GitHub App ID for authentication"
8+
required: true
9+
LE_BOT_PRIVATE_KEY:
10+
description: "GitHub App Private Key for authentication"
11+
required: true
12+
1413
jobs:
1514
manage-issue-header:
1615
runs-on: ubuntu-latest
1716
if: |
17+
github.event.action == 'opened' ||
18+
github.event.action == 'reopened' ||
1819
(github.event.action == 'labeled' && github.event.label.name == 'help wanted') ||
1920
(github.event.action == 'unlabeled' && github.event.label.name == 'help wanted')
2021
steps:
21-
- name: Generate App Token
22+
- name: Generate GitHub token
2223
id: generate-token
2324
uses: tibdex/github-app-token@v2
2425
with:
2526
app_id: ${{ secrets.LE_BOT_APP_ID }}
2627
private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
2728

28-
- name: Checkout called repository
29-
uses: actions/checkout@v3
29+
- name: Checkout .github repository
30+
uses: actions/checkout@v4
3031
with:
3132
repository: learningequality/.github
3233
ref: main
3334
token: ${{ steps.generate-token.outputs.token }}
34-
35+
3536
- name: Setup Node.js
36-
uses: actions/setup-node@v3
37+
uses: actions/setup-node@v4
3738
with:
38-
node-version: '16'
39+
node-version: 20
40+
cache: 'yarn'
3941

4042
- name: Install dependencies
41-
run: npm install
42-
43+
run: yarn install --frozen-lockfile
44+
4345
- name: Run script
44-
id: run-script
45-
uses: actions/github-script@v6
46+
uses: actions/github-script@v7
4647
with:
4748
github-token: ${{ steps.generate-token.outputs.token }}
4849
script: |
4950
const script = require('./scripts/manage-issue-header.js');
50-
return await script({github, context, core});
51+
await script({github, context, core});

scripts/manage-issue-header.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,48 @@ function clearHeader(issueBody) {
2222
return issueBody.substring(0, startIndex) + issueBody.substring(endIndex + HEADER_END_MARKER.length).trimStart();
2323
}
2424

25+
function isIssueHelpWanted(issue) {
26+
if (!issue.labels || !issue.labels.length) {
27+
return false;
28+
}
29+
return issue.labels.some(label => label.name === HELP_WANTED_LABEL);
30+
}
31+
2532
module.exports = async ({ github, context, core }) => {
2633
try {
2734
const repoOwner = context.repo.owner;
2835
const repoName = context.repo.repo;
2936
const issueNumber = context.payload.issue.number;
3037
const actionType = context.payload.action;
31-
const labelName = context.payload.label.name;
32-
33-
const labelAdded = actionType === "labeled";
34-
const labelRemoved = actionType === "unlabeled";
35-
36-
if (!labelAdded && !labelRemoved) {
37-
return;
38-
}
39-
40-
if (labelName !== HELP_WANTED_LABEL) {
41-
return;
38+
const labelName = context.payload.label?.name;
39+
let issue = context.payload.issue;
40+
let header = '';
41+
42+
switch (actionType) {
43+
case 'opened':
44+
// also handle pre-existing 'help wanted' label on transferred issues (processed via 'opened' event in a receiving repository)
45+
header = isIssueHelpWanted(issue) ? HELP_WANTED_HEADER : NON_HELP_WANTED_HEADER;
46+
break;
47+
case 'reopened':
48+
// check for pre-existing 'help wanted' label
49+
header = isIssueHelpWanted(issue) ? HELP_WANTED_HEADER : NON_HELP_WANTED_HEADER;
50+
break;
51+
case 'labeled':
52+
if (labelName === HELP_WANTED_LABEL) {
53+
header = HELP_WANTED_HEADER;
54+
}
55+
break;
56+
case 'unlabeled':
57+
if (labelName === HELP_WANTED_LABEL) {
58+
header = NON_HELP_WANTED_HEADER;
59+
}
60+
break;
61+
default:
62+
core.info(`Unsupported action type '${actionType}' or label '${labelName}'. Skipping.`);
63+
return;
4264
}
4365

44-
const issue = await github.rest.issues.get({
66+
issue = await github.rest.issues.get({
4567
owner: repoOwner,
4668
repo: repoName,
4769
issue_number: issueNumber
@@ -50,11 +72,7 @@ module.exports = async ({ github, context, core }) => {
5072
const currentBody = issue.data.body || "";
5173

5274
let newBody = clearHeader(currentBody);
53-
if (labelAdded) {
54-
newBody = HELP_WANTED_HEADER + newBody;
55-
} else if (labelRemoved) {
56-
newBody = NON_HELP_WANTED_HEADER + newBody;
57-
}
75+
newBody = header + newBody;
5876

5977
await github.rest.issues.update({
6078
owner: repoOwner,

0 commit comments

Comments
 (0)