-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from stakater/add-providers
Add providers
- Loading branch information
Showing
4 changed files
with
64 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Fetch Params | ||
|
||
The fetch params python script uses github, gitlab, and bitbucket apis to fetch required information about a commit such as the PR number. | ||
Use this in a tekton task to get values needed for running a pipeline using pipeline as cide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
import requests | ||
from requests.auth import HTTPBasicAuth | ||
|
||
def send_api_request_github(url, password): | ||
|
||
try: | ||
headers = {"Authorization": f"token {password}"} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
parsed_data = json.loads(response.text) | ||
return parsed_data | ||
else: | ||
print(f"Request failed with status code: {response.status_code}") | ||
print(f"Response content: {response.text}") | ||
return None | ||
except requests.exceptions.RequestException as e: | ||
print(f"Error occurred during the API request: {e}") | ||
return None | ||
|
||
def fetch_params_github(provider, username, password, hash, workspace, repository): | ||
|
||
if provider == "github": | ||
url = f"https://github.com/repos/{workspace}/{repository}/pulls" | ||
print(url) | ||
pull_requests = send_api_request (url, password) | ||
if pull_requests: | ||
for pr in pull_requests: | ||
pull_request_id = pr['number'] | ||
url = f"https://github.com/repos/{workspace}/{repository}/pulls/{pull_request_id}/commits" | ||
commits = send_api_request(url,"", password, "github") | ||
if commits: | ||
for commit in commits: | ||
print(f"Commit SHA: {commit['sha']}") | ||
if commit['sha'] == hash: | ||
print(f"Found hash in PR {pull_request_id}") | ||
found = True | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from fetch_params_bitbucket import fetch_params_bitbucket | ||
from fetch_params_github import fetch_params_github | ||
import argparse | ||
|
||
def find_hash(provider, username, password, hash, workspace, repository): | ||
if provider == "bitbucket": | ||
pr_number = fetch_params_bitbucket(provider, username, password, hash, workspace, repository) | ||
elif provider == "github": | ||
pr_number = fetch_params_github(provider, username, password, hash, workspace, repository) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("provider", help="Name of git provider") | ||
parser.add_argument("username", help="Username for git provider") | ||
parser.add_argument("password", help="Password/Token for provider") | ||
parser.add_argument("hash", help="Hash of the commit that triggered the pipeline") | ||
parser.add_argument("workspace", help="Workspace/Organization") | ||
parser.add_argument("repository", help="Git repository name") | ||
args = parser.parse_args() | ||
find_hash(args.provider, args.username, args.password, args.hash, args.workspace, args.repository) |