-
Notifications
You must be signed in to change notification settings - Fork 84
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
fix: Add fetch for default branch #1031
Changes from 1 commit
10bdbed
0eff1fc
037755a
5efe028
aeadcfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from copy import deepcopy | ||
from pathlib import Path | ||
from typing import Dict, List, Optional | ||
import requests | ||
import jinja2 | ||
|
||
from synthtool import shell, _tracked_paths | ||
|
@@ -58,6 +59,11 @@ def _generic_library(self, directory: str, **kwargs) -> Path: | |
|
||
t = templates.TemplateGroup(self._template_root / directory, self.excludes) | ||
|
||
repo = kwargs["metadata"]["repository"] | ||
github_req = requests.get(f"https://api.github.com/repos/{repo}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
github_req.raise_for_status() | ||
kwargs["metadata"]["repo"]["default_branch"] = github_req.json()["default_branch"] | ||
|
||
# TODO: migrate to python.py once old sample gen is deprecated | ||
if directory == "python_samples": | ||
t.env.globals["get_help"] = lambda filename: shell.run( | ||
|
@@ -353,3 +359,9 @@ def _load_repo_metadata(metadata_file: str = "./.repo-metadata.json") -> Dict: | |
with open(metadata_file) as f: | ||
return json.load(f) | ||
return {} | ||
|
||
def _get_default_branch_name(package_name: str) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this might not be used yet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
r = requests.get(f"https://pypi.org/pypi/{package_name}/json") | ||
r.raise_for_status() | ||
|
||
return r.json()["info"]["version"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- default-branch | ||
pull_request: | ||
name: ci | ||
jobs: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me, but I think it would be worth adding a test here:
https://github.com/googleapis/synthtool/blob/master/tests/test_templates.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test