Skip to content

Commit 0ae2051

Browse files
markmcdcopybara-github
authored andcommitted
Add support for non-master branches.
Not all repos use `master` as their primary branch, and I guess it's nice to support arbitrary branches too? PiperOrigin-RevId: 530582877
1 parent 653fd30 commit 0ae2051

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/tensorflow_docs/tools/nblint/style/tensorflow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ def button_colab(args):
159159
"""Test that the URL in the Colab button matches the file path."""
160160
cell_source = args["cell_source"]
161161
repo = get_arg_or_fail(args["user"], "repo", "<org/name>")
162+
branch = args["user"].get("branch", "master")
162163
docs_dir, rel_path = split_doc_path(args["path"])
163164

164165
# Buttons use OSS URLs.
165166
if str(docs_dir) == "g3doc/en":
166167
docs_dir = pathlib.Path("site/en")
167168

168-
base_url = f"colab.research.google.com/github/{repo}/blob/master"
169+
base_url = f"colab.research.google.com/github/{repo}/blob/{branch}"
169170
this_url = "https://" + str(base_url / docs_dir / rel_path)
170171

171172
if is_button_cell_re.search(cell_source) and cell_source.find(this_url) != -1:
@@ -216,13 +217,14 @@ def button_github(args):
216217
"""Test that the URL in the GitHub button matches the file path."""
217218
cell_source = args["cell_source"]
218219
repo = get_arg_or_fail(args["user"], "repo", "<org/name>")
220+
branch = args["user"].get("branch", "master")
219221
docs_dir, rel_path = split_doc_path(args["path"])
220222

221223
# Buttons use OSS URLs.
222224
if str(docs_dir) == "g3doc/en":
223225
docs_dir = pathlib.Path("site/en")
224226

225-
base_url = f"github.com/{repo}/blob/master"
227+
base_url = f"github.com/{repo}/blob/{branch}"
226228
this_url = "https://" + str(base_url / docs_dir / rel_path)
227229

228230
if is_button_cell_re.search(cell_source) and cell_source.find(this_url) != -1:

0 commit comments

Comments
 (0)