Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: dashboard/dashboard/pinpoint/models/change/repository.py

Issue 3011393002: [pinpoint] Docstrings for models/change/repository.py. (Closed)
Patch Set: "current canonical" Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dashboard/dashboard/pinpoint/models/job.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/dashboard/pinpoint/models/change/repository.py
diff --git a/dashboard/dashboard/pinpoint/models/change/repository.py b/dashboard/dashboard/pinpoint/models/change/repository.py
index 52785829d509928fda34e3d67d8e863c7b8e3217..067f64c4f8c3239ba2ebf342a26833b63d011256 100644
--- a/dashboard/dashboard/pinpoint/models/change/repository.py
+++ b/dashboard/dashboard/pinpoint/models/change/repository.py
@@ -10,11 +10,51 @@ _URLS_TO_NAMES_KEY = 'repository_urls_to_names'
def RepositoryUrl(name):
+ """Returns the URL of a repository, given its short name.
+
+ If a repository moved locations or has multiple locations, a repository can
+ have multiple URLs. The returned URL should be the current canonical one.
+
+ Args:
+ name: The short name of the repository.
+
+ Returns:
+ A URL string, not including '.git'.
+ """
repositories = namespaced_stored_object.Get(_REPOSITORIES_KEY)
+ # We have the 'repository_url' key in case we want to add more fields later.
return repositories[name]['repository_url']
def Repository(url, add_if_missing=False):
+ """Returns the short repository name, given its URL.
+
+ By default, the short repository name is the last part of the URL.
+ E.g. "https://chromium.googlesource.com/v8/v8": "v8"
+ In some cases this is ambiguous, so the names can be manually adjusted.
+ E.g. "../chromium/src": "chromium" and "../breakpad/breakpad/src": "breakpad"
+
+ If a repository moved locations or has multiple locations, multiple URLs can
+ map to the same name. This should only be done if they are exact mirrors and
+ have the same git hashes.
+ "https://webrtc.googlesource.com/src": "webrtc"
+ "https://webrtc.googlesource.com/src/webrtc": "old_webrtc"
+ "https://chromium.googlesource.com/external/webrtc/trunk/webrtc": "old_webrtc"
+
+ Internally, all repositories are stored by short name, which always maps to
+ the current canonical URL, so old URLs are automatically "upconverted".
+
+ Args:
+ url: The repository URL.
+ add_if_missing: If True, also attempts to add the URL to the database with
+ the default name mapping. Throws an exception if there's a name collision.
+
+ Returns:
+ The short name as a string.
+
+ Raises:
+ AssertionError: add_if_missing is True and there's a name collision.
+ """
if url.endswith('.git'):
url = url[:-4]
@@ -28,6 +68,16 @@ def Repository(url, add_if_missing=False):
def _AddRepository(url):
+ """Add a repository URL to the database with the default name mapping.
+
+ The default short repository name is the last part of the URL.
+
+ Returns:
+ The short repository name.
+
+ Raises:
+ AssertionError: The default name is already in the database.
+ """
name = url.split('/')[-1]
# Add to main repositories dict.
« no previous file with comments | « no previous file | dashboard/dashboard/pinpoint/models/job.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698