Compare commits
4 Commits
8bdab1f9db
...
08bd36c133
| Author | SHA1 | Date | |
|---|---|---|---|
| 08bd36c133 | |||
| e8959eea14 | |||
| 7bf6ff373d | |||
| ad3ebecb62 |
@@ -23,6 +23,7 @@ async function ghActionBot() {
|
||||
COMMENT_BODY_REGEXP_FLAGS,
|
||||
COMMENT_ACTOR,
|
||||
PULL_LABEL_FILTER,
|
||||
PULL_LABEL_EXCLUDE,
|
||||
PULL_AUTHOR_FILTER,
|
||||
PULL_RETEST_BODY,
|
||||
ACTION_RETRY_DELAY = 3000,
|
||||
@@ -62,7 +63,7 @@ async function ghActionBot() {
|
||||
}
|
||||
|
||||
// filter on label
|
||||
if (PULL_LABEL_FILTER && !pull.labels.includes(PULL_LABEL_FILTER)) {
|
||||
if (!PULL_LABEL_FILTER.split(',').every(label => pull.labels.includes(label))) {
|
||||
logger.debug(
|
||||
`SKIP PULL #${
|
||||
pull.number
|
||||
@@ -71,6 +72,17 @@ async function ghActionBot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// filter out matching exclusion tags
|
||||
if (PULL_LABEL_EXCLUDE) {
|
||||
const exclude = PULL_LABEL_EXCLUDE.split(',').some(label => pull.labels.includes(label));
|
||||
if (exclude) {
|
||||
logger.debug(
|
||||
`SKIP PULL #${pull.number}: label matches exclusion labels '${PULL_LABEL_EXCLUDE}'`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return { comment, pull };
|
||||
})
|
||||
)).filter(Boolean);
|
||||
|
||||
@@ -5,20 +5,30 @@ function truncate(str, len = 26) {
|
||||
return `${str.slice(0, len)}...`;
|
||||
}
|
||||
|
||||
export default async function getEvents(repo, { body, actor } = {}) {
|
||||
const events = await repo.events.fetch();
|
||||
const getCommentEvents = async (repo, lastEvents) => {
|
||||
// just fetch and return the results
|
||||
if (lastEvents == null) return repo.events.fetch();
|
||||
|
||||
const items = await (async () => {
|
||||
// process 2 pages of events
|
||||
if (events.nextPage) {
|
||||
const moreEvents = await events.nextPage.fetch();
|
||||
return [...events.items, ...moreEvents.items];
|
||||
}
|
||||
// if there is no next page, just return the passed in object
|
||||
if (!lastEvents.nextPage) return lastEvents;
|
||||
|
||||
return events.items;
|
||||
})();
|
||||
// fetch next items and append previous ones
|
||||
const newEvents = await lastEvents.nextPage.fetch();
|
||||
newEvents.items = [...lastEvents.items, ...newEvents.items];
|
||||
return newEvents;
|
||||
};
|
||||
|
||||
return items
|
||||
export default async function getEvents(repo, { body, actor, pages = 4 } = {}) {
|
||||
// create a task array that we can reduce into a promise chain
|
||||
const chain = [];
|
||||
while (chain.length < pages) chain.push('page');
|
||||
|
||||
const events = await chain.reduce(
|
||||
acc => acc.then(res => getCommentEvents(repo, res)),
|
||||
Promise.resolve()
|
||||
);
|
||||
|
||||
return events.items
|
||||
.map(comment => {
|
||||
let skip = false;
|
||||
const isComment = comment.type === 'IssueCommentEvent';
|
||||
|
||||
@@ -5,8 +5,8 @@ const MAX_ITEMS = 1000; // max entries in history
|
||||
const TRUNCATE_AMOUNT = 200; // count of entries to remove when max is hit
|
||||
|
||||
export default class History {
|
||||
constructor() {
|
||||
this.filePath = path.resolve('data', 'history.json');
|
||||
constructor(filename = 'history.json') {
|
||||
this.filePath = path.resolve('data', filename);
|
||||
try {
|
||||
const data = fs.readFileSync(this.filePath);
|
||||
this.db = data.length === 0 ? [] : JSON.parse(data);
|
||||
|
||||
Reference in New Issue
Block a user