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

[GitHub] GitHub file size for a specific branch #8262

Merged

Conversation

PaulaBarszcz
Copy link
Collaborator

@PaulaBarszcz PaulaBarszcz commented Jul 29, 2022

Related issue: #7876

It is my first contribution to Shields - all comments and suggestions are welcome! 😉

Tested locally, gives expected results, some screenshots for example:

image
commit: 345da16
"size": 3572,
https://api.github.com/repos/badges/shields/contents/services/text-formatters.js?ref=345da16

image
branch integration-docs
"size": 3442,
https://api.github.com/repos/badges/shields/contents/services/text-formatters.js?ref=integration-docs

image
tag server-2021-10-04
"size": 3250,
https://api.github.com/repos/badges/shields/contents/services/text-formatters.js?ref=server-2021-10-04

image
tag 2.0.0-beta1
our file is not present in this tag
https://api.github.com/repos/badges/shields/contents/services/text-formatters.js?ref=2.0.0-beta1

If we don't specify the branch/commit/tag, it searches the master branch by default.

On the Shields website locally, it looks like this:

image


The previous endpoint for GitHub file size still works correctly.

@shields-ci
Copy link

shields-ci commented Jul 29, 2022

Messages
📖 ✨ Thanks for your contribution to Shields, @PaulaBarszcz!

Generated by 🚫 dangerJS against d48a49e

@calebcartwright calebcartwright added the service-badge New or updated service badge label Jul 29, 2022
Comment on lines 73 to 75
if (!branch) {
branch = 'master'
}
Copy link
Member

Choose a reason for hiding this comment

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

The default branch for a repo is configurable and most repos now use main. Instead of setting branch explicitly here if it is not supplied, pass a ?ref= param in our API call only if branch is supplied. If the user doesn't supply the param we can leave github to work out the default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @chris48s,
Good point, updated, thanks.

@PaulaBarszcz
Copy link
Collaborator Author

PaulaBarszcz commented Aug 1, 2022

Hi @chris48s,

I see that the test suite failed on my feature branch. Is it something that I can fix?:

GitlabContributors: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.
GitlabLicense: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.

from:
https://app.circleci.com/pipelines/github/badges/shields/14245/workflows/19814146-9649-439a-ab11-7b6899bb2f07/jobs/192075

image

@calebcartwright
Copy link
Member

Hi @chris48s,

I see that the test suite failed on my feature branch. Is it something that I can fix?:

GitlabContributors: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.
GitlabLicense: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.

from: https://app.circleci.com/pipelines/github/badges/shields/14245/workflows/19814146-9649-439a-ab11-7b6899bb2f07/jobs/192075

image

Seems it was specious. I reran the failed jobs and they passed

@PaulaBarszcz
Copy link
Collaborator Author

Hi @chris48s,
I see that the test suite failed on my feature branch. Is it something that I can fix?:

GitlabContributors: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.
GitlabLicense: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.

from: https://app.circleci.com/pipelines/github/badges/shields/14245/workflows/19814146-9649-439a-ab11-7b6899bb2f07/jobs/192075
image

Seems it was specious. I reran the failed jobs and they passed

Ah, ok, thanks :)

I am currently not working on anything on this branch. If there is something that should be changed before a merge to the master branch, I am open to suggestions :)

@repo-ranger repo-ranger bot merged commit fa3839c into badges:master Aug 2, 2022
@chris48s
Copy link
Member

chris48s commented Aug 2, 2022

Ta - merged. Running the full test suite for github is a sufficiently large number of integration tests that sometimes we'll hit a flaky one. You can actually filter this down further if you want. For example, if you run npm run test:services -- --only="githubsize" locally that will run just the github size tests, and you can also use [githubsize] in a PR title.

Comment on lines +64 to +76
if (branch) {
return this._requestJson({
url: `/repos/${user}/${repo}/contents/${path}?ref=${branch}`,
schema,
errorMessages: errorMessagesFor('repo, branch or file not found'),
})
} else {
return this._requestJson({
url: `/repos/${user}/${repo}/contents/${path}`,
schema,
errorMessages: errorMessagesFor('repo or file not found'),
})
}
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but one thing to be aware of for future reference is that we typically like to use the options key on the arg which in turn allows our http client library to handle the conditionality of the query search parameters for us. I gather there's also a need to have slightly different error texts depending on the branch, though that could also be handled with a single call too, e.g.:

    return this._requestJson({
      url: `/repos/${user}/${repo}/contents/${path}`,
      schema,
      options: { searchParams: { ref: branch } },
      errorMessages: errorMessagesFor(
        `repo${branch ? ', branch' : ''} or file not found`
      ),
    })

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That’s neat, I will try to remember about this syntax - thanks ☺️

@PaulaBarszcz PaulaBarszcz deleted the github-file-size-for-specific-branch branch August 3, 2022 05:43
@PaulaBarszcz
Copy link
Collaborator Author

Ta - merged. Running the full test suite for github is a sufficiently large number of integration tests that sometimes we'll hit a flaky one. You can actually filter this down further if you want. For example, if you run npm run test:services -- --only="githubsize" locally that will run just the github size tests, and you can also use [githubsize] in a PR title.

Cool, thanks! I was not sure if it was better to run the whole GitHub test suite or a narrower one, now I know that it would be fine also with a narrower version 😌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants