Skip to content

Commit

Permalink
feat: add comment-or-create action
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP committed Sep 4, 2024
1 parent c22b3eb commit c2fbbda
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/ci-repo-watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ jobs:
REPOSITOY_MARKDOWN_LIST: ${{ env.NEW_REPOSITORIES }}

- if: ${{ env.NEW_REPOSITORIES != 'null' }}
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.token }}
uses: ./comment-or-create
with:
token: ${{ secrets.GITHUB_TOKEN || secrets.token }}
title: New repos in ${{ env.GITHUB_REPOSITORY_OWNER }} found
assignees: CAMOBAP
filename: .github/templates/new-repos.md
comment: |
Review new discovered repositories during run {{ env.GITHUB_SERVER_URL }}/{{ env.GITHUB_REPOSITORY }}/actions/runs/{{ env.GITHUB_RUN_ID }}:
${{ env.NEW_REPOSITORIES }}
And add them to `cimas-config/cimas.yml` with the right set of `files`
64 changes: 64 additions & 0 deletions comment-or-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: comment-or-create
description: |
Action to comment or create issue if missing
inputs:
token:
description: Token
required: true
title:
description: Issue title
required: true
comment:
description: Comment/topic string
required: true
assignees:
description: Usernames to assign
required: true

outputs:
issue:
description: GitHub issue number
value: ${{ steps.comment-or-create.outputs.issue }}

runs:
using: "composite"
steps:
- id: comment-or-create
uses: actions/github-script@v7
with:
github-token: ${{ inputs.token }}
script: |
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const issueTitle = '${{ inputs.title }}';
const issueBody = '${{ inputs.comment }}';
const assignees = '${{ inputs.assignees }}'.split(",").map(user => user.trim());
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
let issueNumber = undefined;
const existingIssue = issues.find(issue => issue.title === issueTitle);
if (existingIssue) {
issueNumber = existingIssue.number;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: issueBody
});
} else {
const newIssue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
assignees: assignees
});
issueNumber = newIssue.data.number;
}
core.setOutput('issue', issueNumber);

0 comments on commit c2fbbda

Please sign in to comment.