Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Upgrade Workflows/Actions #5

Upgrade Workflows/Actions

Upgrade Workflows/Actions #5

Workflow file for this run

name: LGTM Workflow
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check_and_review:
runs-on: ubuntu-latest
steps:
- name: Check for LGTM comment
id: check
uses: actions/github-script@v5
with:
script: |
const prNumber = context.payload.pull_request.number;
const repo = context.repo;
if (context.payload.pull_request.draft) {
console.log('This is a draft PR, skipping checks.');
return false;
}
const comments = await github.issues.listComments({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber
});
let found = false;
for (const comment of comments.data) {
if (comment.body.toLowerCase() === 'lgtm') {
await github.reactions.createForIssueComment({
owner: repo.owner,
repo: repo.repo,
comment_id: comment.id,
content: '+1',
});
found = true;
break;
}
}
return found;
env:
LGTM_FOUND: ${{ steps.check.outputs.result }}
- name: Approve or request changes
id: review
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const github = require('@actions/github');
const core = require('@actions/core');
const context = github.context;
const prNumber = context.payload.pull_request.number;
const repo = context.repo;
const found = process.env.LGTM_FOUND === 'true';
const octokit = github.getOctokit(core.getInput('github-token'));
if (found) {
await octokit.pulls.createReview({
owner: repo.owner,
repo: repo.repo,
pull_number: prNumber,
event: 'APPROVE'
});
} else {
await octokit.pulls.createReview({
owner: repo.owner,
repo: repo.repo,
pull_number: prNumber,
event: 'REQUEST_CHANGES',
body: 'The check failed because no LGTM comment was found.'
});
}