Skip to content

Commit

Permalink
Support orgs other than openshift
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreyd committed Feb 6, 2024
1 parent 4e66b2f commit 5edf74d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 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
21 changes: 11 additions & 10 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,14 +41,14 @@ 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)
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.so.say(f'Unable to find the distgit repo associated with `{self.org/self.repo_name}`: '
f'please check the query and try again')
return None

Expand Down Expand Up @@ -156,7 +157,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 +180,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 +194,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 +378,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 5edf74d

Please sign in to comment.