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

Modify GraphQL query to uniquely identify issues #35

Closed
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
31 changes: 18 additions & 13 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ 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 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}`;

// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
// This finds the issue based on the title, so if that changes, a new issue will be created.
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}) {
issues(first: 100, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
Copy link
Contributor Author

@agriyakhetarpal agriyakhetarpal Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is the maximum limit for the first: query. This can potentially be reduced. However, I would still suggest keeping it to a reasonable amount, because it already has to be >1 to be able to check for titles across issues.

Since it's already running through GitHub API with ${{ github.token }}, I don't think we'll hit any rate limits.

edges {
node {
body
id
number
title
}
}
}
Expand All @@ -76,25 +78,28 @@ runs:
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, variables);
let existingIssue = result.repository.issues.edges.find(edge => edge.node.title === title);

// 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 no issue is found to be open, or if found issue's title doesn't match,
// then we create a new issue. Else, we update the body of the existing issue.
if (!existingIssue) {
github.rest.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: title,
labels: [variables.label],
assignees: assignees
})
});
} else {
// Update the body of the existing issue
github.rest.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.repository.issues.edges[0].node.number,
issue_number: existingIssue.node.number,
body: issue_body
})
});
}
Loading