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 e9359f0
Show file tree
Hide file tree
Showing 2 changed files with 76 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`
67 changes: 67 additions & 0 deletions comment-or-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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
env:
INPUT_TITLE: ${{ inputs.title }}
INPUT_COMMENT: ${{ inputs.comment }}
INPUT_ASSIGNEES: ${{ inputs.assignees }}
uses: actions/github-script@v7
with:
github-token: ${{ inputs.token }}
script: |
const issueTitle = process.env.INPUT_TITLE;
const issueBody = process.env.INPUT_COMMENT;
const assignees = process.env.INPUT_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;
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 e9359f0

Please sign in to comment.