зеркало из https://github.com/microsoft/ghcrawler.git
Code review changes
This commit is contained in:
Родитель
2d15805828
Коммит
2c87136362
|
@ -160,7 +160,6 @@ const pull_request_commit_comment = {
|
|||
const pull_request_commit = {
|
||||
_type: 'pull_request_commit',
|
||||
pull_request_commit_comments: collection(pull_request_commit_comment),
|
||||
repo: self,
|
||||
author: self,
|
||||
committer: self
|
||||
};
|
||||
|
@ -204,7 +203,7 @@ const pull_request = {
|
|||
reviews: review,
|
||||
review_comments: review_comment,
|
||||
statuses: collection(status),
|
||||
commits: collection(commit),
|
||||
pull_request_commits: collection(pull_request_commit),
|
||||
issue: issue,
|
||||
issue_comments: collection(issue_comment)
|
||||
};
|
||||
|
|
|
@ -209,24 +209,22 @@ class GitHubProcessor {
|
|||
commit(request, isPullRequestCommit = false) {
|
||||
const document = request.document;
|
||||
const context = request.context;
|
||||
let repoUrn = null;
|
||||
if (isPullRequestCommit) {
|
||||
// if this is a PR commit, put it in a central spot for the repo and setup the qualifier so comments go there too
|
||||
repoUrn = `urn:repo:${context.qualifier.split(':')[2]}`;
|
||||
context.qualifier = `${repoUrn}:pull_request_commit`;
|
||||
request.linkResource('self', `${context.qualifier}:${document.sha}`);
|
||||
request.linkSiblings(`${repoUrn}:pull_request_commits`);
|
||||
request.addSelfLink('sha');
|
||||
request.linkSiblings(`${context.qualifier}:pull_request_commits`);
|
||||
request.linkResource('pull_request', context.qualifier);
|
||||
} else if (context.qualifier.includes('PushEvent')) {
|
||||
repoUrn = `urn:repo:${context.qualifier.split(':')[2]}`;
|
||||
const repoUrn = `urn:repo:${context.qualifier.split(':')[2]}`;
|
||||
context.qualifier = `${repoUrn}:commit`;
|
||||
request.linkResource('self', `${context.qualifier}:${document.sha}`);
|
||||
request.linkSiblings(`${repoUrn}:commits`);
|
||||
this._addRoot(request, 'repo', 'repo', document.url.replace(/\/commits\/.*/, ''), repoUrn);
|
||||
} else {
|
||||
request.addSelfLink('sha');
|
||||
repoUrn = context.qualifier;
|
||||
const repoUrn = context.qualifier;
|
||||
request.linkSiblings(`${context.qualifier}:commits`);
|
||||
this._addRoot(request, 'repo', 'repo', document.url.replace(/\/commits\/.*/, ''), repoUrn);
|
||||
}
|
||||
this._addRoot(request, 'repo', 'repo', document.url.replace(/\/commits\/.*/, ''), repoUrn);
|
||||
|
||||
// Most often there actually are no comments. Get the comments if we think there will be some and this resource is being processed (vs. traversed).
|
||||
// Note that if we are doing event processing, new comments will be added to the list dynamically so the only reason we need to refetch the
|
||||
|
@ -254,6 +252,7 @@ class GitHubProcessor {
|
|||
return document;
|
||||
}
|
||||
|
||||
// It looks like there are only pull request review comments now. Pull request commit comments may not exist anymore.
|
||||
pull_request_commit_comment(request) {
|
||||
return this.commit_comment(request, true);
|
||||
}
|
||||
|
@ -264,13 +263,9 @@ class GitHubProcessor {
|
|||
const document = request.document;
|
||||
const context = request.context;
|
||||
request.addSelfLink();
|
||||
if (isPullRequest) {
|
||||
request.linkResource('pull_request_commit', context.qualifier);
|
||||
request.linkSiblings(`${context.qualifier}:pull_request_commit_comments`);
|
||||
} else {
|
||||
request.linkResource('commit', context.qualifier);
|
||||
request.linkSiblings(`${context.qualifier}:commit_comments`);
|
||||
}
|
||||
const commitName = isPullRequest ? 'pull_request_commit' : 'commit';
|
||||
request.linkResource(commitName, context.qualifier);
|
||||
request.linkSiblings(`${context.qualifier}:${commitName}_comments`);
|
||||
|
||||
this._addRoot(request, 'user', 'user');
|
||||
return document;
|
||||
|
@ -302,7 +297,7 @@ class GitHubProcessor {
|
|||
}
|
||||
|
||||
if (document._links.commits && document.commits) {
|
||||
this._addRelation(request, 'commits', 'pull_request_commit', document._links.commits.href);
|
||||
this._addCollection(request, 'pull_request_commits', 'pull_request_commit', document._links.commits.href);
|
||||
}
|
||||
|
||||
// link and queue the related issue. Getting the issue will bring in the comments for this PR
|
||||
|
|
|
@ -423,56 +423,6 @@ describe('Commit processing', () => {
|
|||
expectQueued(queue, expected);
|
||||
}
|
||||
|
||||
it('should link and queue pull request commit correctly without comments', () => {
|
||||
testPullRequestCommit(false);
|
||||
});
|
||||
|
||||
it('should link and queue pull request commit correctly with comments', () => {
|
||||
testPullRequestCommit(true);
|
||||
});
|
||||
|
||||
function testPullRequestCommit(hasComments = false) {
|
||||
request = createRequest('pull_request_commit', 'http://foo/commit');
|
||||
request.context = { qualifier: 'urn:repo:12:pull_request_commit:77cb09b5b5' };
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
request.document = {
|
||||
_metadata: { links: {} },
|
||||
sha: '77cb09b5b5',
|
||||
url: 'http://repo/12/commits/77cb09b5b5',
|
||||
commit: { comment_count: 0 },
|
||||
author: { id: 7, url: 'http://user/7' },
|
||||
committer: { id: 15, url: 'http://user/15' }
|
||||
};
|
||||
if (hasComments) {
|
||||
request.document.commit.comment_count = 1;
|
||||
request.document.comments_url = 'http://comments';
|
||||
}
|
||||
request.processMode = 'process';
|
||||
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.pull_request_commit(request);
|
||||
const links = {
|
||||
self: { href: 'urn:repo:12:pull_request_commit:77cb09b5b5', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:12:pull_request_commits', type: 'collection' },
|
||||
author: { href: 'urn:user:7', type: 'resource' },
|
||||
committer: { href: 'urn:user:15', type: 'resource' },
|
||||
repo: { href: 'urn:repo:12', type: 'resource' },
|
||||
pull_request_commit_comments: { href: 'urn:repo:12:pull_request_commit:77cb09b5b5:pull_request_commit_comments', type: 'collection' }
|
||||
};
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/7', path: '/author' },
|
||||
{ type: 'user', url: 'http://user/15', path: '/committer' },
|
||||
{ type: 'repo', url: 'http://repo/12', path: '/repo' }
|
||||
];
|
||||
if (hasComments) {
|
||||
expected.push({ type: 'pull_request_commit_comments', url: 'http://comments', qualifier: 'urn:repo:12:pull_request_commit:77cb09b5b5', path: '/pull_request_commit_comments' });
|
||||
}
|
||||
expectQueued(queue, expected);
|
||||
}
|
||||
|
||||
it('should link and queue PushEvent with commits', () => {
|
||||
const request = createRequest('PushEvent', 'http://foo/events/123');
|
||||
const queue = [];
|
||||
|
@ -506,6 +456,57 @@ describe('Commit processing', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Pull request commit processing', () => {
|
||||
it('should link and queue pull request commit correctly without comments', () => {
|
||||
testPullRequestCommit(false);
|
||||
});
|
||||
|
||||
it('should link and queue pull request commit correctly with comments', () => {
|
||||
testPullRequestCommit(true);
|
||||
});
|
||||
|
||||
function testPullRequestCommit(hasComments = false) {
|
||||
request = createRequest('pull_request_commit', 'http://foo/commit');
|
||||
request.context = { qualifier: 'urn:repo:12:pull_request:9' };
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
request.document = {
|
||||
_metadata: { links: {} },
|
||||
sha: '77cb09b5b5',
|
||||
url: 'http://repo/12/commits/77cb09b5b5',
|
||||
commit: { comment_count: 0 },
|
||||
author: { id: 7, url: 'http://user/7' },
|
||||
committer: { id: 15, url: 'http://user/15' }
|
||||
};
|
||||
if (hasComments) {
|
||||
request.document.commit.comment_count = 1;
|
||||
request.document.comments_url = 'http://comments';
|
||||
}
|
||||
request.processMode = 'process';
|
||||
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.pull_request_commit(request);
|
||||
const links = {
|
||||
self: { href: 'urn:repo:12:pull_request:9:pull_request_commit:77cb09b5b5', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:12:pull_request:9:pull_request_commits', type: 'collection' },
|
||||
author: { href: 'urn:user:7', type: 'resource' },
|
||||
committer: { href: 'urn:user:15', type: 'resource' },
|
||||
pull_request : { href: 'urn:repo:12:pull_request:9', type: 'resource' },
|
||||
pull_request_commit_comments: { href: 'urn:repo:12:pull_request:9:pull_request_commit:77cb09b5b5:pull_request_commit_comments', type: 'collection' }
|
||||
};
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/7', path: '/author' },
|
||||
{ type: 'user', url: 'http://user/15', path: '/committer' }
|
||||
];
|
||||
if (hasComments) {
|
||||
expected.push({ type: 'pull_request_commit_comments', url: 'http://comments', qualifier: 'urn:repo:12:pull_request:9:pull_request_commit:77cb09b5b5', path: '/pull_request_commit_comments' });
|
||||
}
|
||||
expectQueued(queue, expected);
|
||||
}
|
||||
});
|
||||
|
||||
describe('Commit comment processing', () => {
|
||||
it('should link and queue correctly', () => {
|
||||
const request = createRequest('commit_comment', 'http://repo/commit/comment');
|
||||
|
@ -534,33 +535,6 @@ describe('Commit comment processing', () => {
|
|||
expectQueued(queue, expected);
|
||||
});
|
||||
|
||||
it('should link and queue pull request commit comment correctly', () => {
|
||||
const request = createRequest('pull_request_commit_comment', 'http://repo/commit/comment');
|
||||
request.context = { qualifier: 'urn:repo:12:pull_request_commit:a1b1' };
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
request.document = {
|
||||
_metadata: { links: {} },
|
||||
id: 37,
|
||||
user: { id: 7, url: 'http://user/7' }
|
||||
};
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.pull_request_commit_comment(request);
|
||||
|
||||
const links = {
|
||||
self: { href: 'urn:repo:12:pull_request_commit:a1b1:pull_request_commit_comment:37', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:12:pull_request_commit:a1b1:pull_request_commit_comments', type: 'collection' },
|
||||
pull_request_commit: { href: 'urn:repo:12:pull_request_commit:a1b1', type: 'resource' },
|
||||
user: { href: 'urn:user:7', type: 'resource' },
|
||||
}
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/7', path: '/user' },
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
|
||||
it('should link and queue CommitCommentEvent', () => {
|
||||
const request = createRequest('CommitCommentEvent', 'http://foo/pull');
|
||||
const queue = [];
|
||||
|
@ -595,6 +569,35 @@ describe('Commit comment processing', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Pull request commit comment processing', () => {
|
||||
it('should link and queue pull request commit comment correctly', () => {
|
||||
const request = createRequest('pull_request_commit_comment', 'http://repo/commit/comment');
|
||||
request.context = { qualifier: 'urn:repo:12:pull_request:7:pull_request_commit:a1b1' };
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
request.document = {
|
||||
_metadata: { links: {} },
|
||||
id: 37,
|
||||
user: { id: 7, url: 'http://user/7' }
|
||||
};
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.pull_request_commit_comment(request);
|
||||
|
||||
const links = {
|
||||
self: { href: 'urn:repo:12:pull_request:7:pull_request_commit:a1b1:pull_request_commit_comment:37', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:12:pull_request:7:pull_request_commit:a1b1:pull_request_commit_comments', type: 'collection' },
|
||||
pull_request_commit: { href: 'urn:repo:12:pull_request:7:pull_request_commit:a1b1', type: 'resource' },
|
||||
user: { href: 'urn:user:7', type: 'resource' },
|
||||
}
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/7', path: '/user' },
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Deployment processing', () => {
|
||||
it('should link and queue correctly', () => {
|
||||
const request = createRequest('deployment', 'http://foo');
|
||||
|
@ -664,7 +667,7 @@ describe('Pull Request processing', () => {
|
|||
repo: { href: 'urn:repo:17', type: 'resource' },
|
||||
reviews: { href: 'urn:repo:12:pull_request:13:reviews', type: 'collection' },
|
||||
review_comments: { href: 'urn:repo:12:pull_request:13:review_comments', type: 'collection' },
|
||||
commits: { href: 'urn:repo:12:pull_request:13:commits:pages:*', type: 'relation' },
|
||||
pull_request_commits: { href: 'urn:repo:12:pull_request:13:pull_request_commits', type: 'collection' },
|
||||
statuses: { href: 'urn:repo:12:commit:funkySHA:statuses', type: 'collection' },
|
||||
issue: { href: 'urn:repo:12:issue:13', type: 'resource' },
|
||||
issue_comments: { href: 'urn:repo:12:issue:13:issue_comments', type: 'collection' }
|
||||
|
@ -680,7 +683,7 @@ describe('Pull Request processing', () => {
|
|||
{ type: 'reviews', url: 'http://pull_request/13/reviews', qualifier: 'urn:repo:12:pull_request:13', path: '/reviews' },
|
||||
{ type: 'review_comments', url: 'http://review_comments', qualifier: 'urn:repo:12:pull_request:13', path: '/review_comments' },
|
||||
{ type: 'statuses', url: 'http://statuses/funkySHA', qualifier: 'urn:repo:12:pull_request:13', path: '/statuses' },
|
||||
{ type: 'commits', url: 'http://commits', qualifier: 'urn:repo:12:pull_request:13', path: '/commits' }
|
||||
{ type: 'pull_request_commits', url: 'http://commits', qualifier: 'urn:repo:12:pull_request:13', path: '/pull_request_commits' }
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче