Skip to content

fix: Add fetch for default branch #1031

Merged
bcoe merged 5 commits intomasterfrom
add-default-branch
Apr 16, 2021
Merged

fix: Add fetch for default branch #1031
bcoe merged 5 commits intomasterfrom
add-default-branch

Conversation

@billyjacobson
Copy link
Copy Markdown
Contributor

Add fetch for default branch so autogen files can use the correct default branch during migration

@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 8, 2021
@billyjacobson billyjacobson requested a review from bcoe April 8, 2021 17:23
Copy link
Copy Markdown

@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.

This is looking pretty reasonable to me, with the caveat that I think it would be good to add a test.

I think you could use something like requests-mock so that you don't need to actually care about the traffic to GitHub.

Comment thread synthtool/gcp/common.py Outdated
return json.load(f)
return {}

def _get_default_branch_name(package_name: str) -> str:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks like this might not be used yet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread synthtool/gcp/common.py Outdated

t = templates.TemplateGroup(self._template_root / directory, self.excludes)

repo = kwargs["metadata"]["repository"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a test

Comment thread synthtool/gcp/common.py Outdated
t = templates.TemplateGroup(self._template_root / directory, self.excludes)

repo = kwargs["metadata"]["repository"]
github_req = requests.get(f"https://api.github.com/repos/{repo}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@SurferJeffAtGoogle Will this be problematic for owl-bot (as it's not hermetic)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think Jeff is out til Friday? Is there anyone else we can ask about this? Or do you have thoughts on this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To me this seems like it's probably okay, as it will be applied in the post-processor, and will stay consistent for the repo itself?

@billyjacobson billyjacobson requested a review from bcoe April 9, 2021 15:23
@billyjacobson billyjacobson marked this pull request as ready for review April 12, 2021 15:02
@billyjacobson billyjacobson requested a review from a team April 12, 2021 15:02
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2021
@bcoe bcoe merged commit 898b38a into master Apr 16, 2021
@bcoe bcoe deleted the add-default-branch branch April 16, 2021 00:13
@bcoe
Copy link
Copy Markdown

bcoe commented Apr 16, 2021

@billyjacobson thank you for adding this 👍 sorry it took a while to land, the beginning of the week was a bit swamped.

Comment thread tests/test_common.py

def test_get_default_branch():
with requests_mock.Mocker() as m:
m.get(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I really appreciate that you added a test for this 🆗

@SurferJeffAtGoogle
Copy link
Copy Markdown
Contributor

Sorry I didn't chime in on this sooner.

This is causing @sofisl and I problems because we're trying to generate templated code for a new library, that doesn't have a corresponding github repo yet.

With this PR, _generic_library() fetches data from the network during template generation. That's not what I imagined it would ever do. That also means it will fail whenever the network is flaky. It's very fragile.

@bcoe and @billyjacobson Can we observe or encode the default branch without making network requests?

@billyjacobson
Copy link
Copy Markdown
Contributor Author

billyjacobson commented May 11, 2021 via email

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.

5 participants