Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow parametrizing the issue title #38

Merged
merged 25 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
});
}
Loading