Skip to content

Commit

Permalink
test release trigge
Browse files Browse the repository at this point in the history
  • Loading branch information
supatsara-wat committed Oct 16, 2023
1 parent b511478 commit 1cf75f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 50 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/pr-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ on:
pull_request_target:
types: [opened, reopened, synchronize]

on:
release:
types: [published]

jobs:

detect-unsafe:
detect-unsafe-pr:
runs-on: ubuntu-latest
name: Check pull request with changes
if: github.event_name == 'pull_request_target'
steps:
- name: Check PR
uses: supatsara-wat/DepSafe@release_feature
Expand All @@ -17,4 +22,18 @@ jobs:
repo: ${{ github.event.repository.name }}
pr_number: ${{ github.event.number }}
token: ${{ secrets.GITHUB_TOKEN }}
type: "PR"
type: "check_pr"

check-unsafe-release:
runs-on: ubuntu-latest
name: Check pull request with changes
if: github.event_name == 'release'
steps:
- name: Check Opened PRs
uses: supatsara-wat/DepSafe@release_feature
with:
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pr_number: ${{ github.event.number }}
token: ${{ secrets.GITHUB_TOKEN }}
type: "check_release"
32 changes: 8 additions & 24 deletions binary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9873,8 +9873,8 @@ async function alertMessages(owner, repo, pr_number, octokit, changedJsonfiles,

async function setLabels(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles) {
const labels = [];
if (changedJsonfiles.length >= 1) labels.push(':warning: unsafe **package.json**');
if (changedJSfiles.length >= 1) labels.push(':warning: unsafe **.js**');
if (changedJsonfiles.length >= 1) labels.push(':warning: unsafe [ package.json ]');
if (changedJSfiles.length >= 1) labels.push(':warning: unsafe [ .js ]');

if (labels.length) {
await octokit.rest.issues.addLabels({
Expand All @@ -9889,29 +9889,11 @@ async function setLabels(owner, repo, pr_number, octokit, changedJsonfiles, chan
const main = async () => {
try {

/**
* Now we need to create an instance of Octokit which will use to call
* GitHub's REST API endpoints.
* We will pass the token as an argument to the constructor. This token
* will be used to authenticate our requests.
* You can find all the information about how to use Octokit here:
* https://octokit.github.io/rest.js/v18
**/

/**
* We need to fetch the list of files that were changes in the Pull Request
* and store them in a variable.
* We use octokit.paginate() to automatically loop over all the pages of the
* results.
* Reference: https://octokit.github.io/rest.js/v18#pulls-list-files
*/

const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const pr_number = core.getInput('pr_number', { required: true });
const token = core.getInput('token', { required: true });
const triggerType = core.getInput('type', { required: true });

const octokit = new github.getOctokit(token);


Expand All @@ -9921,7 +9903,7 @@ const main = async () => {
state: "open"
});

let prNums = triggerType === 'PR'
let prNums = triggerType === 'check_pr'
? pullRequests.map(pr => pr.number) : [pr_number];

for (const num of prNums) {
Expand Down Expand Up @@ -9956,9 +9938,11 @@ const main = async () => {
}

if (changedJsonfiles.length >= 1 || changedJSfiles.length >= 1) {
if (triggerType === 'PR') {
alertMessages(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles);
setLabels(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles);
if (triggerType === 'check_pr') {
alertMessages(owner, repo, num, octokit, changedJsonfiles, changedJSfiles);
}
else {
setLabels(owner, repo, num, octokit, changedJsonfiles, changedJSfiles);
}
}

Expand Down
32 changes: 8 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ async function alertMessages(owner, repo, pr_number, octokit, changedJsonfiles,

async function setLabels(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles) {
const labels = [];
if (changedJsonfiles.length >= 1) labels.push(':warning: unsafe **package.json**');
if (changedJSfiles.length >= 1) labels.push(':warning: unsafe **.js**');
if (changedJsonfiles.length >= 1) labels.push(':warning: unsafe [ package.json ]');
if (changedJSfiles.length >= 1) labels.push(':warning: unsafe [ .js ]');

if (labels.length) {
await octokit.rest.issues.addLabels({
Expand All @@ -79,29 +79,11 @@ async function setLabels(owner, repo, pr_number, octokit, changedJsonfiles, chan
const main = async () => {
try {

/**
* Now we need to create an instance of Octokit which will use to call
* GitHub's REST API endpoints.
* We will pass the token as an argument to the constructor. This token
* will be used to authenticate our requests.
* You can find all the information about how to use Octokit here:
* https://octokit.github.io/rest.js/v18
**/

/**
* We need to fetch the list of files that were changes in the Pull Request
* and store them in a variable.
* We use octokit.paginate() to automatically loop over all the pages of the
* results.
* Reference: https://octokit.github.io/rest.js/v18#pulls-list-files
*/

const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const pr_number = core.getInput('pr_number', { required: true });
const token = core.getInput('token', { required: true });
const triggerType = core.getInput('type', { required: true });

const octokit = new github.getOctokit(token);


Expand All @@ -111,7 +93,7 @@ const main = async () => {
state: "open"
});

let prNums = triggerType === 'PR'
let prNums = triggerType === 'check_pr'
? pullRequests.map(pr => pr.number) : [pr_number];

for (const num of prNums) {
Expand Down Expand Up @@ -146,9 +128,11 @@ const main = async () => {
}

if (changedJsonfiles.length >= 1 || changedJSfiles.length >= 1) {
if (triggerType === 'PR') {
alertMessages(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles);
setLabels(owner, repo, pr_number, octokit, changedJsonfiles, changedJSfiles);
if (triggerType === 'check_pr') {
alertMessages(owner, repo, num, octokit, changedJsonfiles, changedJSfiles);
}
else {
setLabels(owner, repo, num, octokit, changedJsonfiles, changedJSfiles);
}
}

Expand Down

0 comments on commit 1cf75f4

Please sign in to comment.