Skip to content

Commit

Permalink
allow parametrizing the issue title (#38)
Browse files Browse the repository at this point in the history
* 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 <agriyakhetarpal@users.noreply.github.com>

* 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 <agriyakhetarpal@users.noreply.github.com>
  • Loading branch information
keewis and agriyakhetarpal authored Jul 7, 2024
1 parent 4960d70 commit 123161b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ In case you don't like the default title for new issues, this setting can be use
issue-title: "Nightly CI failed"
```

The title can also be parametrized, in which case a separate issue will be opened for each variation of the title.

### issue label

optional. Default: `CI`
Expand Down
47 changes: 25 additions & 22 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ inputs:
required: true
issue-title:
description: >-
Title of issue being created or updated
Title of issue being created or updated. Can be a parametrized string, in which case
a new issue will be opened for all variations.
required: false
default: "⚠️ Nightly upstream-dev CI failed ⚠️"
issue-label:
Expand Down Expand Up @@ -51,17 +52,25 @@ runs:
script: |
const fs = require('fs');
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
const title = "${{ inputs.issue-title }}"
const assignees = "${{inputs.assignees}}".split(",")
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`
const assignees = "${{inputs.assignees}}".split(",");
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: "${{ inputs.issue-label }}",
creator: "app/github-actions",
title: "${{ inputs.issue-title }}"
};
const query_string = `repo:${variables.owner}/${variables.name} author:${variables.creator} label:${variables.label} is:open in:title ${variables.title}`;
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
repository(owner: $owner, name: $name) {
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
const query = `query {
search(query: "${query_string}", type:ISSUE, first: 1) {
edges {
node {
... on Issue {
body
id
number
Expand All @@ -71,30 +80,24 @@ runs:
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: "${{ inputs.issue-label }}",
creator: "github-actions[bot]"
}
const result = await github.graphql(query, variables)
const result = await github.graphql(query);
// If no issue is open, create a new issue,
// else update the body of the existing issue.
if (result.repository.issues.edges.length === 0) {
if (result.search.edges.length === 0) {
github.rest.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: title,
title: variables.title,
labels: [variables.label],
assignees: assignees
})
});
} else {
github.rest.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.repository.issues.edges[0].node.number,
issue_number: result.search.edges[0].node.number,
body: issue_body
})
});
}

0 comments on commit 123161b

Please sign in to comment.