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

Add PR comment if the action contributing guidelines have been met #10

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
43 changes: 43 additions & 0 deletions .github/workflows/reusable-build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,46 @@ jobs:
.addRaw(instructionsWithLinks)
.write();
core.setFailed(instructions);

# ----------------------------------------------------
# Add comment if Contributing Guidelines are satisfied
# ----------------------------------------------------
- name: Add comment if contributing guidelines are satisfied
if: env.HAS_CODE_CHANGES == 'true' && env.NEEDS_BUILD_COMMIT == 'false' && env.NEEDS_README_COMMIT == 'false'
uses: actions/github-script@v7
with:
script: |

// Setup vars for the script to use
const hasBuildStep = ${{ env.HAS_BUILD_STEP }};

const contribId = '${{ inputs.readme-contribution-id }}';
const contributionLink = `https://github.com/${{ github.repository }}${contribId}`;
const contributingTitle = contribId.replace('#', '').split('-').map(w => { return w.slice(0, 1).toUpperCase() + w.slice(1) }).join(' ');

const exampleId = '${{ inputs.readme-examples-id }}';
const readmeLink = `${{ github.event.pull_request.head.repo.html_url }}/blob/${{ github.event.pull_request.head.ref }}/${{ env.README }}`;
const readmeExampleLink = `${readmeLink}${exampleId}`;
const readmeExampleTitle = exampleId.replace('#', '').split('-').map(w => { return w.slice(0, 1).toUpperCase() + w.slice(1) }).join(' ');

// Construct the prComment
let prComment = `The action's [${contributingTitle} Guidelines](${contributionLink}) have been met:
- The action's version in the [${readmeExampleTitle}](${readmeExampleLink}) section of [${{ env.README }}](${readmeLink}) has been updated to \`@${{ env.NEXT_VERSION }}\``

if (hasBuildStep){
prComment += `
- The action has been recompiled (if needed) by running the build command from the root of the repository`;
}

// Comment on PR for branches. A fork's GH_TOKEN only has 'read' permission on all scopes so a comment cannot be made.
if (!${{ env.IS_FORK }}) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: prComment
})
}

// Add workflow summary
core.summary.addRaw(prComment).write();
Loading