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

refactor(github): get files from commits w/out PRs #825

Merged
merged 3 commits into from
Mar 19, 2021

Conversation

joeldodge79
Copy link
Collaborator

commitsSinceShaRest queries the REST API to get files associated directly
with a history of commits. This solves the problem that commitsWithFiles
has with processing a multi-commit PR: it ends up assigning all the
files for the PR to every commit in the PR.

I have not tested it but I think it could replace commitsWithFiles (
but not commitsWithLabels since there are no PRs as part of this query).

@joeldodge79 joeldodge79 requested a review from a team as a code owner March 12, 2021 18:36
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 12, 2021
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #825 (a6ad28a) into master (63a8d57) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #825      +/-   ##
==========================================
+ Coverage   93.68%   93.73%   +0.05%     
==========================================
  Files          64       64              
  Lines        9067     9148      +81     
  Branches      964      928      -36     
==========================================
+ Hits         8494     8575      +81     
  Misses        570      570              
  Partials        3        3              
Impacted Files Coverage Δ
src/github.ts 90.12% <100.00%> (+0.51%) ⬆️
src/manifest.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63a8d57...a6ad28a. Read the comment docs.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few nits.

while (moreFiles) {
const response = (await this.request(
'GET /repos/{owner}/{repo}/commits/{ref}{?page}',
{owner: this.owner, repo: this.repo, ref, page}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have a per_page?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see code comment in feedback

src/github.ts Outdated
break;
}
files.push(...commitFiles.map(f => f.filename ?? ''));
if (commitFiles.length < 300) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this slightly confusing, does the API contract say that it will return up to 300 files in the first request?

Mind just adding a comment that links to the API docs describing the limits of this API? I think there's also an upper-bound limit of 3000 files (unlikely for many people to bump into).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -504,7 +504,7 @@ export class Manifest {
if (fromSha === undefined) {
fromSha = (await this.getConfigJson())['bootstrap-sha'];
}
return this.gh.commitsSinceSha(fromSha);
return this.gh.commitsSinceShaRest(fromSha);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any food reason for us to keep commitsSinceSha?

Perhaps just open a tracking ticket to get rid of it? (I understand not wanting to do it as part of this work).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #830

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👏

commitsSinceShaRest queries the REST API to get files associated directly
with a history of commits. This solves the problem that commitsWithFiles
has with processing a multi-commit PR: it ends up assigning all the
files for the PR to every commit in the PR.

I have not tested it but I think it could replace commitsWithFiles (
but not commitsWithLabels since there are no PRs as part of this query).
@joeldodge79 joeldodge79 force-pushed the github-commits-since-sha-rest branch from 9d952db to e96564b Compare March 18, 2021 18:15
@joeldodge79 joeldodge79 requested a review from bcoe March 18, 2021 18:18
Comment on lines +338 to +340
// TODO: it is more robust to follow the link.next headers (in case
// GitHub ever changes the pattern) OR use ocktokit pagination for this
// endpoint when https://git.io/JmVll is addressed.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is kind of hacky/rookie... but do you mind if I just add a tracking issue to harden/future-proof it (maybe add to #830)?

@bcoe bcoe merged commit 535b5f9 into googleapis:master Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants