Skip to content

Commit

Permalink
Fixed and improved DevRel Notify Action
Browse files Browse the repository at this point in the history
  • Loading branch information
simonerom committed Aug 12, 2024
1 parent 0c50d68 commit a392f3c
Showing 1 changed file with 50 additions and 27 deletions.
77 changes: 50 additions & 27 deletions .github/workflows/notify-devrel.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Folder Change Notification
name: DevRel Notification

on:
push:
Expand All @@ -17,42 +17,65 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3 # Updated to the latest version
uses: actions/checkout@v3

- name: Create or Update Issue
uses: actions/github-script@v6 # Ensure it's compatible with Node.js 16 or 20
uses: actions/github-script@v6
with:
script: |
const { owner, repo } = context.repo;
const issueTitle = 'Changes detected in examples, smartcontracts, or docs folder';
const issueTitle = 'Checkout new changes in Examples or Docs';
const issueBody = `@simonerom Changes were detected in the 'examples', 'smartcontracts', or 'docs' folder. Please review the changes.`;
// Determine if this was triggered by a push or pull request
const isPR = !!context.payload.pull_request;
const triggerLink = isPR
? context.payload.pull_request.html_url
: `${context.payload.repository.html_url}/commit/${context.sha}`;
const triggerDescription = isPR
? context.payload.pull_request.body || "No PR description provided."
: context.payload.head_commit.message || "No commit message provided.";
const issues = await github.issues.listForRepo({
owner,
repo,
state: 'open',
labels: 'notification'
});
const triggerType = isPR ? "PR" : "commit";
const issueBody = `@simonerom Changes were detected in the 'docs', 'examples', or 'smartcontracts' folder.
Please review the changes and update the docs portal if required.
The changes were triggered by this ${triggerType}:
[${triggerLink}](${triggerLink})
_${triggerDescription}_`;
if (issues.data.length === 0) {
// Create a new issue if no open issues with the label exist
await github.issues.create({
try {
const issues = await github.rest.issues.listForRepo({
owner,
repo,
title: issueTitle,
body: issueBody,
labels: ['notification']
});
} else {
// Comment on the first open issue with the label
const issueNumber = issues.data[0].number;
await github.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: issueBody
state: 'open',
labels: 'notification'
});
if (issues.data.length === 0) {
// Create a new issue if no open issues with the label exist
await github.rest.issues.create({
owner,
repo,
title: issueTitle,
body: issueBody,
labels: ['notification']
});
} else {
// Comment on the first open issue with the label
const issueNumber = issues.data[0].number;
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: issueBody
});
}
} catch (error) {
console.error('Error creating or updating issue:', error);
throw error;
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Ensure the GitHub token is available as an environment variable
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} # Using PAT_TOKEN if needed for permissions

0 comments on commit a392f3c

Please sign in to comment.