Skip to content

Commit

Permalink
add newAtLatestPrInfo handling (#4215)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm1957 authored Oct 26, 2024
1 parent 2b498e1 commit 19cebae
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/newAtLatestPrInfo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will triage pull requests and apply a label based on the
# paths that are modified in the pull request.

name: New at LATEST PR Info

#
# WARNING:
# ** Do NOT run untrusted code when using pull_request_target **
# pull_request_target is needed as pull_request does not provide secrets and so no
# labeling of PR is possible.
#
on:
pull_request_target:
types: [labeled, unlabeled]

jobs:
stableBrandNewInfo:
name: new at latest PR info
if: |
github.repository == 'ioBroker/ioBroker.repositories'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm i
- run: npm run newAtLatestPrInfo
env:
OWN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/stable0DayPrInfo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

jobs:
stableBrandNewInfo:
name: stable brand new info
name: stable 0-day PR info
if: |
github.repository == 'ioBroker/ioBroker.repositories'
Expand Down
108 changes: 108 additions & 0 deletions lib/newAtLatestPrInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict';
const fs = require('node:fs');
const {
addComment,
deleteComment,
getLabels,
getAllComments,
} = require('./common');

function getPullRequestNumber() {
if (process.env.GITHUB_REF && process.env.GITHUB_REF.match(/refs\/pull\/\d+\/merge/)) {
const result = /refs\/pull\/(\d+)\/merge/g.exec(process.env.GITHUB_REF);
if (!result) {
throw new Error('Reference not found.');
}
return result[1];
}
if (process.env.GITHUB_EVENT_PATH) {
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));
return event.pull_request ? event.pull_request.number : (event.issue ? event.issue.number : '');
}

throw new Error('Reference not found. process.env.GITHUB_REF and process.env.GITHUB_EVENT_PATH are not set!');
}

async function checkLabel(prID, label) {
const lbls = await getLabels(prID);
for ( const lbl of lbls) {
if (lbl.name === label) {
return true;
}
}
return false;
}

async function doIt() {
const prID = getPullRequestNumber();

console.log(`Process PR ${prID}`);

if (!prID) {
console.error('Cannot find PR');
return Promise.reject('Cannot find PR');
}

const labelIsSet = await checkLabel (prID, 'New at LATEST');
console.log (`label New at LATEST is ${labelIsSet ? '' : 'NOT '}set.`);

const gitComments = await getAllComments(prID);
let exists = gitComments.find(comment => comment.body.includes('## ioBroker repository information about New at LATEST tagging'));
console.log (`informational comment ${labelIsSet ? 'exists' : 'does NOT exist.'}`);

if (exists && !labelIsSet) {
try {
console.log(`deleting comment ${exists.id} from PR ${prID}`);
await deleteComment(prID, exists.id);
} catch (e) {
console.error(`warning: cannot delete comment from PR ${prID}:`);
console.log(` ${e}`);
}
}

if (!exists && labelIsSet) {
let body = `## ioBroker repository information about New at LATEST tagging\n\n`;

body += `Thanks for spending your time and providing a new adapter for ioBroker.\n\n`;

body += `Your adapter will get a manual review as soon as possible. Please stand by - this might last one or two weeks. `;
body += `Feel free to continue your work and create new releases. `:
body += `You do NOT need to close or update this PR in case of new releases.\n\n`;

body += `In the meantime please check any feedback issues logged by automatic adapter checker and try to fix them.`
body += `Especially check the following information if not yet done:\n`;

body += `- https://github.com/ioBroker/ioBroker.repositories?tab=readme-ov-file#requirements-for-adapter-to-get-added-to-the-latest-repository\n`;
body += `- https://github.com/ioBroker/ioBroker.repositories?tab=readme-ov-file#development-and-coding-best-practices\n`;
body += `- https://github.com/iobroker-community-adapters/responsive-design-initiative/tree/main#responsive-design-initiative\n`;

body += `You will find the results of the review and eventually issues / suggestions as a comment to this PR. `;
body += `So please keep this PR watched.\n\n`;

body += `If you have any urgent questions feel free to ask.\n\n`;


try {
console.log(`adding information comment to PR ${prID}`);
await addComment(prID, body);
} catch (e) {
console.error(`warning: cannot add comment to PR ${prID}:`);
console.log(` ${e}`);
};
}

return 'done';
}

// activate for debugging purposes
// process.env.GITHUB_REF = 'refs/pull/2725/merge';
// process.env.OWN_GITHUB_TOKEN = 'insert token';
// process.env.GITHUB_EVENT_PATH = __dirname + '/../event.json';

console.log(`process.env.GITHUB_REF = ${process.env.GITHUB_REF}`);
console.log(`process.env.GITHUB_EVENT_PATH = ${process.env.GITHUB_EVENT_PATH}`);
console.log(`process.env.OWN_GITHUB_TOKEN = ${(process.env.OWN_GITHUB_TOKEN || '').length}`);

doIt()
.then(result => console.log(result))
.catch(e => console.error(e));
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"checkArchived": "node lib/checkArchived.js",
"checkNpm": "node lib/checkNpm.js",
"manualAction": "node lib/manualAction.js",
"newAtLastesPrInfo": "node lib/newAtLastestPrInfo.js",
"setLabels": "node lib/setLabels.js",
"setStableTag": "node lib/setStableTag.js",
"setTag": "node lib/setTag.js",
Expand Down

0 comments on commit 19cebae

Please sign in to comment.