-
Notifications
You must be signed in to change notification settings - Fork 0
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 #28 from LukaszSielski/extract_commons
Extract commons
- Loading branch information
Showing
4 changed files
with
35 additions
and
44 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
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,15 @@ | ||
import subprocess | ||
from subprocess import check_output, CalledProcessError | ||
|
||
class AzCli: | ||
|
||
def tag_work_items(work_items_ids: list[str], tag: str): | ||
update_result = {} | ||
for work_item_id in work_items_ids: | ||
output = None | ||
try: | ||
output = check_output(f'az boards work-item update --id {work_item_id} --fields "System.Tags={tag}', shell=True, stderr=subprocess.STDOUT) | ||
except CalledProcessError as e: | ||
update_result.update({work_item_id: e.stderr}) | ||
update_result.update({work_item_id: output}) | ||
print(update_result) |
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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import re | ||
import subprocess | ||
import json | ||
from enum import Enum | ||
|
||
class PrState(str, Enum): | ||
OPEN = 'open' | ||
CLOSED = 'closed' | ||
MERGED = 'merged' | ||
ALL = 'all' | ||
|
||
class GitHubCli: | ||
|
||
def extract_pr_body(self, commit_sha: str) -> str: | ||
def extract_pr_body(self, commit_sha: str, pr_state: PrState) -> str: | ||
prDetails = None | ||
try: | ||
prDetails = subprocess.check_output(f'gh pr list --json body --state merged --search {commit_sha}', shell=True, text=True) | ||
prDetails = subprocess.check_output(f'gh pr list --json body --state {pr_state.value} --search {commit_sha}', shell=True, text=True) | ||
except subprocess.CalledProcessError as e: | ||
raise Exception(f'Failed to retrieve PR body! {e.stderr}') | ||
prDetailsJson = json.loads(prDetails) | ||
print(prDetailsJson) | ||
return prDetailsJson[0]['body'] if len(prDetailsJson) != 0 else '' | ||
|
||
def extract_data_from_pr_body(self, commit_sha: str, pattern: re.Pattern) -> list[str]: | ||
print(self.extract_pr_body(commit_sha)) | ||
return re.findall(pattern, self.extract_pr_body(commit_sha)) | ||
|
||
|
||
|
||
|
||
|
||
def extract_data_by_pattern_from_pr_body(self, commit_sha: str, pr_state: PrState, pattern: re.Pattern) -> list[str]: | ||
return re.findall(pattern, self.extract_pr_body(commit_sha, pr_state)) |
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