Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Handle malformed comments #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
.env
private-key.pem
scratch.js
notes/
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@ module.exports = robot => {
const q = `label:"${freeze.config.labelName}" repo:${owner}/${repo}`;

context.github.search.issues({q}).then(resp => {
resp.data.items.forEach(issue => {
context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
return freeze.getLastFreeze(resp.data);
}).then(lastFreezeComment => {
if (freeze.unfreezable(lastFreezeComment)) {
freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment));
}
if (resp.data.total_count > 0) {
resp.data.items.forEach(issue => {
context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
return freeze.getLastFreeze(resp.data);
}).then(lastFreezeComment => {
if (Object.prototype.hasOwnProperty.call(lastFreezeComment, 'body')) {
if (freeze.unfreezable(lastFreezeComment)) {
freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment));
}
} else {
robot.log(new Date() + ': ' + issue.comments_url + ' didn\'t find the snooze comment');
}
});

});
});
} else {
console.log(new Date() + ': No issues found to thaw at this time');
}
});
console.log('scheduled thaw run complete');
}
Expand Down
40 changes: 33 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ perform: true
},
search: {
issues: expect.createSpy().andReturn(Promise.resolve({
data:{items: [{comments_url:'https://api.github.com/repos/baxterthehacker/public-repo/issues/2/comments',
labels:[{
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/probot:freeze',
name: 'probot:freeze',
color: 'fc2929'
}]}]
data:{
total_count: 1,
incomplete_results: false,
items: [{comments_url:'https://api.github.com/repos/baxterthehacker/public-repo/issues/2/comments',
labels:[{
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/probot:freeze',
name: 'probot:freeze',
color: 'fc2929'
}]}]
}})) // Q:'label:' + this.labelName
}
};
Expand Down Expand Up @@ -165,7 +168,7 @@ perform: true
});
});

it('test visitor activation', async () => {
it('test scheduled thaw success', async () => {
await robot.receive({
event: 'schedule',
payload: {
Expand Down Expand Up @@ -200,6 +203,29 @@ perform: true
});
});

it('test scheduled thaw failure', async () => {
github.search.issues = expect.createSpy().andReturn(Promise.resolve({
data:{
total_count: 0,
incomplete_results: false,
items: []
}
})); // Q:'label:' + this.labelName

await robot.receive({
event: 'schedule',
payload: {
action: 'repository',
repository: {
owner: {
login:'baxterthehacker'
},
name:'public-repo'
},
installation: {
id: 13055
}}});
});
it('test valid comments', async () => {
const defaultFreezeDuration = 7;
const validMessages = [
Expand Down