зеркало из https://github.com/microsoft/ghcrawler.git
handle legacy PR comment events
This commit is contained in:
Родитель
233ba54aac
Коммит
854ce52044
|
@ -588,12 +588,34 @@ class GitHubProcessor {
|
|||
}
|
||||
|
||||
PullRequestReviewCommentEvent(request) {
|
||||
if (!request.document.payload.pull_request) {
|
||||
// this is a legacy event so tack on the event and queue up a fetch of the pull request to be processed
|
||||
// together so the stored event can have the right pull request link (id is missing in the old events).
|
||||
const context = { originalDocument: request.document };
|
||||
request.queue('LegacyPullRequestReviewCommentEvent', request.document.payload.comment.pull_request_url, request.policy, context);
|
||||
return null;
|
||||
}
|
||||
let [, repo, payload] = this._addEventBasics(request);
|
||||
const qualifier = `urn:repo:${repo}:pull_request:${payload.pull_request.id}`;
|
||||
this._addEventResourceContains(request, repo, 'comment', 'review_comment', qualifier);
|
||||
return this._addEventResourceContains(request, repo, 'pull_request');
|
||||
}
|
||||
|
||||
LegacyPullRequestReviewCommentEvent(request) {
|
||||
const pullRequestDocument = request.document;
|
||||
request.document = request.context.originalDocument;
|
||||
// Tweak the old event to look like a new one, do the normal processing and revert before storing.
|
||||
request.type = 'PullRequestReviewCommentEvent';
|
||||
request.document.payload.pull_request = {
|
||||
url: pullRequestDocument.url,
|
||||
id: pullRequestDocument.id
|
||||
};
|
||||
const result = this.PullRequestReviewCommentEvent(request);
|
||||
delete request.document.payload.pull_request;
|
||||
request.type = 'LegacyPullRequestReviewCommentEvent';
|
||||
return result;
|
||||
}
|
||||
|
||||
PushEvent(request) {
|
||||
let [document] = this._addEventBasics(request);
|
||||
// TODO figure out what to do with the commits
|
||||
|
|
|
@ -570,18 +570,11 @@ describe('Pull request/review comment processing', () => {
|
|||
expectQueued(queue, expected);
|
||||
});
|
||||
|
||||
it('should link and queue PullRequestReviewCommentEvent', () => {
|
||||
const request = createRequest('PullRequestReviewCommentEvent', 'http://foo/pull');
|
||||
function testPullRequestReviewCommentEvent(request, method) {
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
const payload = {
|
||||
comment: { id: 7, url: 'http://review_comment/7' },
|
||||
pull_request: { id: 1, url: 'http://pull_request/1' }
|
||||
}
|
||||
request.document = createEvent('PullRequestReviewCommentEvent', payload);
|
||||
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.PullRequestReviewCommentEvent(request);
|
||||
const document = processor[method](request);
|
||||
|
||||
const links = {
|
||||
self: { href: 'urn:repo:4:PullRequestReviewCommentEvent:12345', type: 'resource' },
|
||||
|
@ -602,6 +595,35 @@ describe('Pull request/review comment processing', () => {
|
|||
{ type: 'pull_request', url: 'http://pull_request/1', qualifier: 'urn:repo:4', path: '/pull_request' }
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
}
|
||||
|
||||
it('should link and queue PullRequestReviewCommentEvent', () => {
|
||||
const request = createRequest('PullRequestReviewCommentEvent', 'http://foo/pull');
|
||||
const payload = {
|
||||
comment: { id: 7, url: 'http://review_comment/7' },
|
||||
pull_request: { id: 1, url: 'http://pull_request/1' }
|
||||
}
|
||||
request.document = createEvent('PullRequestReviewCommentEvent', payload);
|
||||
testPullRequestReviewCommentEvent(request, 'PullRequestReviewCommentEvent');
|
||||
});
|
||||
|
||||
it('should link and queue LegacyPullRequestReviewCommentEvent', () => {
|
||||
const request = createRequest('PullRequestReviewCommentEvent', 'http://foo/pull');
|
||||
const payload = {
|
||||
comment: { id: 7, url: 'http://review_comment/7', pull_request_url: 'http://pull_request/1' }
|
||||
}
|
||||
request.document = createEvent('PullRequestReviewCommentEvent', payload);
|
||||
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.PullRequestReviewCommentEvent(request);
|
||||
|
||||
// test that the new request got queued and that the doc has the right stuff
|
||||
|
||||
const newRequest = queue.pop();
|
||||
newRequest.document = {id: 1, url: 'http://pull_request/1'}
|
||||
testPullRequestReviewCommentEvent(newRequest, 'LegacyPullRequestReviewCommentEvent');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче