Skip to content

Commit

Permalink
Merge pull request #173 from thegreyd/support_orgs_pr_info
Browse files Browse the repository at this point in the history
Support github orgs other than openshift
  • Loading branch information
openshift-merge-bot[bot] authored Feb 6, 2024
2 parents 4e66b2f + 324eb2f commit 4410d00
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
4 changes: 1 addition & 3 deletions artbotlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

ERRATA_TOOL_URL = 'https://errata.devel.redhat.com'

GITHUB_API = "https://api.github.com/repos"

GITHUB_API_OPENSHIFT = f"{GITHUB_API}/openshift"
GITHUB_API_REPO_URL = "https://api.github.com/repos"

ART_DASH_API_ROUTE = "https://art-dash-server-art-dashboard-server.apps.artc2023.pc3z.p1.openshiftapps.com/api/v1"

Expand Down
6 changes: 4 additions & 2 deletions artbotlib/pipeline_image_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def github_distgit_mappings(version: str) -> dict:
for line in out.splitlines():
github, distgit = line.split(": ")
reponame = github.split("/")[-1]
orgname = github.split("/")[-2]
name = f'{orgname}/{reponame}'
if github not in mappings:
mappings[reponame] = [distgit]
mappings[name] = [distgit]
else:
mappings[reponame].append(distgit)
mappings[name].append(distgit)

if not mappings:
logger.warning('No github-distgit mapping found in %s', version)
Expand Down
30 changes: 16 additions & 14 deletions artbotlib/pr_in_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
import artbotlib.exectools
from artbotlib import util, pipeline_image_util
from artbotlib.exceptions import NullDataReturned, BrewNVRNotFound
from artbotlib.constants import BREW_TASK_STATES, BREW_URL, GITHUB_API_OPENSHIFT, ART_DASH_API_ROUTE, \
from artbotlib.constants import BREW_TASK_STATES, BREW_URL, GITHUB_API_REPO_URL, ART_DASH_API_ROUTE, \
RELEASE_CONTROLLER_URL, RELEASE_CONTROLLER_STREAM_PATH


class PrInfo:
def __init__(self, so, repo_name, pr_id, version, arch, component):
def __init__(self, so, org, repo_name, pr_id, version, arch, component):
self.logger = logging.getLogger(__class__.__name__)
self.so = so
self.org = org
self.repo_name = repo_name
self.pr_id = pr_id
self.pr_url = f'https://github.com/openshift/{repo_name}/pull/{pr_id}'
self.pr_url = f'https://github.com/{org}/{repo_name}/pull/{pr_id}'

self.version = version
self.arch = arch if arch else 'amd64'
Expand All @@ -40,23 +41,24 @@ def get_distgit(self):
mappings = pipeline_image_util.github_distgit_mappings(self.version)
except NullDataReturned as e:
self.logger.warning('Exception raised while getting github/distgit mappings: %s', e)
self.so.say(f'Could not retrieve distgit name for {self.repo_name}')
self.so.say(f'Could not retrieve distgit name for {self.org}/{self.repo_name}')
util.please_notify_art_team_of_error(self.so, e)
return None

repo_mappings = mappings.get(self.repo_name, None)
repo_with_org = f'{self.org}/{self.repo_name}'
repo_mappings = mappings.get(repo_with_org, None)
if not repo_mappings:
self.logger.warning(f'No distgit mapping for repo {self.repo_name}')
self.so.say(f'Unable to find the distgit repo associated with `{self.repo_name}`: '
self.logger.warning(f'No distgit mapping for repo {repo_with_org}')
self.so.say(f'Unable to find the distgit repo associated with `{repo_with_org}`: '
f'please check the query and try again')
return None

# Multiple components build from the same upstream
if len(repo_mappings) > 1:
# The user must explicitly provide the component name
if not self.component:
self.logger.warning('Multiple components build from %s: one must be specified', self.repo_name)
self.so.say(f'Multiple components build from `{self.repo_name}`: '
self.logger.warning('Multiple components build from %s: one must be specified', repo_with_org)
self.so.say(f'Multiple components build from `{repo_with_org}`: '
f'please specify the one you\'re interested in and try again')
return None

Expand Down Expand Up @@ -156,7 +158,7 @@ def get_commit_time(self, commit) -> str:
Return the timestamp associated with a commit: e.g. "2022-10-21T19:48:29Z"
"""

url = f"{GITHUB_API_OPENSHIFT}/{self.repo_name}/commits/{commit}"
url = f"{GITHUB_API_REPO_URL}/{self.org}/{self.repo_name}/commits/{commit}"
self.logger.info('Fetching url %s', url)

response = requests.get(url, headers=self.header)
Expand All @@ -179,7 +181,7 @@ def get_commits_after(self, commit) -> list:
"""

datetime = self.get_commit_time(commit)
url = f"{GITHUB_API_OPENSHIFT}/{self.repo_name}/commits?sha=release-{self.version}&since={datetime}"
url = f"{GITHUB_API_REPO_URL}/{self.org}/{self.repo_name}/commits?sha=release-{self.version}&since={datetime}"

commits = util.github_api_all(url)

Expand All @@ -193,7 +195,7 @@ def pr_merge_commit(self):
Return the merge commit SHA associated with a PR
"""

url = f"{GITHUB_API_OPENSHIFT}/{self.repo_name}/pulls/{self.pr_id}"
url = f"{GITHUB_API_REPO_URL}/{self.org}/{self.repo_name}/pulls/{self.pr_id}"
self.logger.info('Fetching url %s', url)

response = requests.get(url, headers=self.header)
Expand Down Expand Up @@ -377,5 +379,5 @@ async def run(self):
f'will not look into nightlies nor releases...')


def pr_info(so, repo, pr_id, major, minor, arch, component):
asyncio.new_event_loop().run_until_complete(PrInfo(so, repo, pr_id, f'{major}.{minor}', arch, component).run())
def pr_info(so, org, repo, pr_id, major, minor, arch, component):
asyncio.new_event_loop().run_until_complete(PrInfo(so, org, repo, pr_id, f'{major}.{minor}', arch, component).run())
2 changes: 1 addition & 1 deletion artbotlib/pr_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def pr_status(so, user_id, org, repo, pr_id):
so.say(f'Ok <@{user_id}>, I\'ll respond here when the PR merges')

pr_url = f'https://github.com/{org}/{repo}/pull/{pr_id}'
api_endpoint = f'{constants.GITHUB_API}/{org}/{repo}/pulls/{pr_id}'
api_endpoint = f'{constants.GITHUB_API_REPO_URL}/{org}/{repo}/pulls/{pr_id}'

start = time.time()
variables.active_slack_objects.add(so)
Expand Down
2 changes: 1 addition & 1 deletion artbotlib/regex_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def map_command_to_regex(so, plain_text, user_id):
"example": "Watch https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12345"
},
{
'regex': r'^pr info \s*(https://)*(github.com/)*(openshift/)*(?P<repo>[a-zA-Z0-9-]+)(/pull/)(?P<pr_id>\d+)(?: component (?P<component>[a-zA-Z0-9-]+))? in %(major_minor)s(?: for arch (?P<arch>[a-zA-Z0-9-]+))?$' % re_snippets,
'regex': r'^pr info \s*(https://)*(github.com/)*(?P<org>[a-zA-Z0-9-]+)\/*(?P<repo>[a-zA-Z0-9-]+)(/pull/)(?P<pr_id>\d+)(?: component (?P<component>[a-zA-Z0-9-]+))? in %(major_minor)s(?: for arch (?P<arch>[a-zA-Z0-9-]+))?$' % re_snippets,
'flag': re.I,
'function': pr_info,
"example": "pr info https://github.com/openshift/ptp-operator/pull/281 component ptp-operator in 4.12 for arch amd64"
Expand Down

0 comments on commit 4410d00

Please sign in to comment.