Skip to content

Commit 123161b

Browse files
allow parametrizing the issue title (#38)
* try querying the title * declare the title as a parameter * trigger CI * pass the title * try using the search connection * try combining before passing to the query * use braces * pass as a query object * move the entire query construction to a separate variable * fix the label * remove a wrong semicolon * use a different parameter name * remove the extra query level * adapt to the changed variables and result structure * document the change * add semicolons at the end of each line Co-authored-by: Agriya Khetarpal <[email protected]> * try going back to assembling the string within the query construction * typo * more semicolons * refer to the variables object whenever necessary * more semicolon * try removing the braces * try doing the string interpolation in js * add back the quotes * only search for open issues --------- Co-authored-by: Agriya Khetarpal <[email protected]>
1 parent 4960d70 commit 123161b

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ In case you don't like the default title for new issues, this setting can be use
7575
issue-title: "Nightly CI failed"
7676
```
7777

78+
The title can also be parametrized, in which case a separate issue will be opened for each variation of the title.
79+
7880
### issue label
7981

8082
optional. Default: `CI`

action.yaml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ inputs:
88
required: true
99
issue-title:
1010
description: >-
11-
Title of issue being created or updated
11+
Title of issue being created or updated. Can be a parametrized string, in which case
12+
a new issue will be opened for all variations.
1213
required: false
1314
default: "⚠️ Nightly upstream-dev CI failed ⚠️"
1415
issue-label:
@@ -51,17 +52,25 @@ runs:
5152
script: |
5253
const fs = require('fs');
5354
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
54-
const title = "${{ inputs.issue-title }}"
55-
const assignees = "${{inputs.assignees}}".split(",")
56-
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
57-
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`
55+
const assignees = "${{inputs.assignees}}".split(",");
56+
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
57+
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`;
58+
59+
const variables = {
60+
owner: context.repo.owner,
61+
name: context.repo.repo,
62+
label: "${{ inputs.issue-label }}",
63+
creator: "app/github-actions",
64+
title: "${{ inputs.issue-title }}"
65+
};
66+
const query_string = `repo:${variables.owner}/${variables.name} author:${variables.creator} label:${variables.label} is:open in:title ${variables.title}`;
5867
5968
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
60-
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
61-
repository(owner: $owner, name: $name) {
62-
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
63-
edges {
64-
node {
69+
const query = `query {
70+
search(query: "${query_string}", type:ISSUE, first: 1) {
71+
edges {
72+
node {
73+
... on Issue {
6574
body
6675
id
6776
number
@@ -71,30 +80,24 @@ runs:
7180
}
7281
}`;
7382
74-
const variables = {
75-
owner: context.repo.owner,
76-
name: context.repo.repo,
77-
label: "${{ inputs.issue-label }}",
78-
creator: "github-actions[bot]"
79-
}
80-
const result = await github.graphql(query, variables)
83+
const result = await github.graphql(query);
8184
8285
// If no issue is open, create a new issue,
8386
// else update the body of the existing issue.
84-
if (result.repository.issues.edges.length === 0) {
87+
if (result.search.edges.length === 0) {
8588
github.rest.issues.create({
8689
owner: variables.owner,
8790
repo: variables.name,
8891
body: issue_body,
89-
title: title,
92+
title: variables.title,
9093
labels: [variables.label],
9194
assignees: assignees
92-
})
95+
});
9396
} else {
9497
github.rest.issues.update({
9598
owner: variables.owner,
9699
repo: variables.name,
97-
issue_number: result.repository.issues.edges[0].node.number,
100+
issue_number: result.search.edges[0].node.number,
98101
body: issue_body
99-
})
102+
});
100103
}

0 commit comments

Comments
 (0)