Skip to content

Commit

Permalink
Merge pull request #53 from Renato66/52-error
Browse files Browse the repository at this point in the history
fix: checking body before continue
  • Loading branch information
Renato66 authored Oct 31, 2023
2 parents 48d9124 + 2cbe083 commit a855782
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
15 changes: 11 additions & 4 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ const compareLabels = (labels) => {
synonymsObject[synonym.toLowerCase()] = label;
});
}
console.log(synonymsObject);
const hasLabels = (line) => {
const selectedLabels = line.match(labelsRegex) || [];
return selectedLabels.map(elem => {
console.log('aqui', elem);
return (synonymsObject[elem.toLowerCase()] ||
labels.find(label => label.toLowerCase() === elem.toLowerCase()) ||
elem);
Expand All @@ -58,18 +56,27 @@ const compareLabels = (labels) => {
}
};
exports.compareLabels = compareLabels;
const parseAutoLabel = (body) => {
const autoLabelRegex = new RegExp(/<!-- AUTO-LABEL:START -->(?<label>(\s*\w.+|\n)*?)\s*<!-- AUTO-LABEL:END -->/, 'gm');
const autoLabels = body.match(autoLabelRegex);
if (!autoLabels)
return body;
const replaceAutoLabelByLabelValue = autoLabel => autoLabel.replace(autoLabelRegex, '$1').trim();
return autoLabels.map(replaceAutoLabelByLabelValue).join(' ');
};
const getIssueLabels = (body, labels) => {
let selectedLabels = [];
let hasLabels = compareLabels(labels);
const ignoreComments = getIgnoreComments();
const parsedBody = parseAutoLabel(body);
if (ignoreComments) {
const noCommentaryBody = body.replace(/\<!--(.|\n)*?-->/g, '');
const noCommentaryBody = parsedBody.replace(/\<!--(.|\n)*?-->/g, '');
hasLabels(noCommentaryBody).map(elem => {
selectedLabels.push(elem);
});
}
else {
hasLabels(body).map(elem => {
hasLabels(parsedBody).map(elem => {
selectedLabels.push(elem);
});
}
Expand Down
9 changes: 7 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ const { getRepoLabels, addLabels } = require('./github');
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log('*** running renato66/auto-label version 2.1.2 ***');
console.log('*** running renato66/auto-label version 2.3.1 ***');
const token = core.getInput('repo-token', { required: true });
const client = new github.GitHub(token);
const issue = github.context.payload.issue;
if (issue === undefined) {
throw new Error('Issue undefined');
console.log('Issue undefined');
return;
}
if (issue.body === undefined) {
console.log('Issue body undefined');
return;
}
console.log('Getting repository labels...');
const repoLabels = yield getRepoLabels(client);
Expand Down
9 changes: 7 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const {getRepoLabels, addLabels} = require('./github')

export async function run() {
try {
console.log('*** running renato66/auto-label version 2.3.0 ***')
console.log('*** running renato66/auto-label version 2.3.1 ***')
const token = core.getInput('repo-token', {required: true})
const client = new github.GitHub(token)
const issue = github.context.payload.issue
if (issue === undefined) {
throw new Error('Issue undefined')
console.log('Issue undefined')
return
}
if (issue.body === undefined) {
console.log('Issue body undefined')
return
}
console.log('Getting repository labels...')
const repoLabels: string = await getRepoLabels(client)
Expand Down

0 comments on commit a855782

Please sign in to comment.