From 04a974912c32eadd7f6dc5d462a8fe9f77fadcc4 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Fri, 14 Dec 2018 09:29:25 -0500 Subject: Checks Sub Project Leads Fatih Pointed out to me the existence of ptl's of sub projects, which show up differently in the INFO.yaml files. This commit also adds support for gerrit.opnfv.org and git.opnfv.org links. I don't remember why we were only accepting github links, but that seems strange. Change-Id: Ica64c4ee7d5c0ce4fa6bfbcbabb1c4ca7cf06018 Signed-off-by: Parker Berberian --- src/workflow/models.py | 85 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 8 deletions(-) (limited to 'src/workflow') diff --git a/src/workflow/models.py b/src/workflow/models.py index 966582c..bed6f52 100644 --- a/src/workflow/models.py +++ b/src/workflow/models.py @@ -26,13 +26,11 @@ from booking.models import Booking class BookingAuthManager(): LFN_PROJECTS = ["opnfv"] # TODO - def parse_url(self, info_url): - """ - will return the PTL in the INFO file on success, or None - """ + def parse_github_url(self, url): + project_leads = [] try: - parts = info_url.split("/") - if parts[0].find("http") > -1: # the url include http(s):// + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// parts = parts[2:] if parts[-1] != "INFO.yaml": return None @@ -47,13 +45,84 @@ class BookingAuthManager(): info_file = requests.get(url, timeout=15).text info_parsed = yaml.load(info_file) ptl = info_parsed.get('project_lead') - if not ptl: + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) + + except Exception: + pass + + return project_leads + + def parse_gerrit_url(self, url): + project_leads = [] + try: + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// + parts = parts[2:] + if "f=INFO.yaml" not in parts[-1].split(";"): + return None + if "gerrit.opnfv.org" not in parts[0]: return None - return ptl + # now to download and parse file + url = "https://" + "/".join(parts) + info_file = requests.get(url, timeout=15).text + info_parsed = yaml.load(info_file) + ptl = info_parsed.get('project_lead') + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) except Exception: return None + return project_leads + + def parse_opnfv_git_url(self, url): + project_leads = [] + try: + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// + parts = parts[2:] + if "INFO.yaml" not in parts[-1]: + return None + if "git.opnfv.org" not in parts[0]: + return None + if parts[-2] == "tree": + parts[-2] = "plain" + # now to download and parse file + url = "https://" + "/".join(parts) + info_file = requests.get(url, timeout=15).text + info_parsed = yaml.load(info_file) + ptl = info_parsed.get('project_lead') + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) + + except Exception: + return None + + return project_leads + + def parse_url(self, info_url): + """ + will return the PTL in the INFO file on success, or None + """ + if "github" in info_url: + return self.parse_github_url(info_url) + + if "gerrit.opnfv.org" in info_url: + return self.parse_gerrit_url(info_url) + + if "git.opnfv.org" in info_url: + return self.parse_opnfv_git_url(info_url) + def booking_allowed(self, booking, repo): """ This is the method that will have to change whenever the booking policy changes in the Infra -- cgit 1.2.3-korg