Skip to content

proof of concept for GitHub action that opens an issue for a PR #937

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

Draft
wants to merge 2 commits into
base: 2023.06-software.eessi.io
Choose a base branch
from
Draft
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
52 changes: 52 additions & 0 deletions .github/workflows/create_issue_on_pr_opened.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create Issue on PR Opened

on:
pull_request:
types: [opened]
Copy link
Member

Choose a reason for hiding this comment

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

I think @laraPPr has played around with this to only trigger when certain file types are touched (in our case easystack files)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should limit that, yes. Only easystack files may be too few, though. Should be easy to figure out for which files bot jobs need to run.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was using this action for that https://github.com/dorny/paths-filter. I'm now looking to see if I can strip what we need from in it. So that we don't have to rely on external actions that much.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This pr includes the new filter #949


permissions:
contents: read # to fetch code (actions/checkout)
issues: write # to create an associated issue (if necessary)

jobs:
create-issue:
runs-on: ubuntu-latest
steps:
- name: Create an issue
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

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

We better explicitly define the permissions in the workflow file. This is the full set available:

permissions:
  actions: read|write|none
  attestations: read|write|none
  checks: read|write|none
  contents: read|write|none
  deployments: read|write|none
  id-token: write|none
  issues: read|write|none
  discussions: read|write|none
  packages: read|write|none
  pages: read|write|none
  pull-requests: read|write|none
  repository-projects: read|write|none
  security-events: read|write|none
  statuses: read|write|none

so we would just need:

permissions:
  contents: read  # to fetch code (actions/checkout)
  issues: write  # to create an associated issue (if necessary)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added in 47e14cf

script: |
const title = `New PR opened: #${context.payload.pull_request.number} - ${context.payload.pull_request.title}`;
const body = `
A new pull request has been opened!

**Title:** ${context.payload.pull_request.title}
**Author:** ${context.payload.pull_request.user.login}

**Link to PR:** ${context.payload.pull_request.html_url}

<details><summary>Click for details & help</summary>

Authorized maintainers may send commands by adding new comments to this issue. A comment can contain multiple commands each starting at the beginning of a line and having the format <code>bot: COMMANDS [ARGS]</code>

The table below lists the commands that are currently supported:
| command | description |
| ------- | ----------- |
| help | prints short usage information |
| show_config | shows config information |
| status | shows status information of builds |
| build ARGS | instructs to build software as defined by the linked PR and with the one or more of the arguments:<br/>architecture, instance, repository, accelerator, exportvariable |

For more information see [building software for EESSI](https://www.eessi.io/docs/bot/#build-test-deploy-bot)
</details>
`;

const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
});

console.log(`Created issue: ${issue.data.html_url}`);