Skip to content

Commit

Permalink
customize args for decorator
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Feb 15, 2023
1 parent b57393d commit 89160a5
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions pull-request.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def retry(attempts=5, timeout=30):
We assume rate limiting is in minutes, so we set timeout to 30.
"""

def decorator(func):
def inner(*args, **kwargs):
attempt = 0
Expand All @@ -55,9 +54,7 @@ def inner(*args, **kwargs):
time.sleep(sleep)
attempt += 1
return func(*args, **kwargs)

return inner

return decorator


Expand Down Expand Up @@ -97,7 +94,8 @@ def parse_into_list(values):


def set_env_and_output(name, value):
"""helper function to echo a key/value pair to the environement file
"""
Helper function to echo a key/value pair to the environement file
Parameters:
name (str) : the name of the environment variable
Expand All @@ -111,7 +109,7 @@ def set_env_and_output(name, value):
environment_file.write("%s=%s\n" % (name, value))


@retry
@retry(attempts=5, timeout=60)
def open_pull_request(title, body, target, source, is_draft=False, can_modify=True):
"""
Open pull request opens a pull request with a given body and content,
Expand Down Expand Up @@ -145,9 +143,10 @@ def open_pull_request(title, body, target, source, is_draft=False, can_modify=Tr
return response


@retry
@retry()
def update_pull_request(entry, title, body, target, state=None):
"""Given an existing pull request, update it.
"""
Given an existing pull request, update it.
Parameters:
entry (dict) : the pull request metadata
Expand Down Expand Up @@ -175,7 +174,8 @@ def update_pull_request(entry, title, body, target, state=None):


def set_pull_request_groups(response):
"""Given a response for an open or updated PR, set metadata
"""
Given a response for an open or updated PR, set metadata
Parameters:
response (requests.Response) : a requests response, unparsed
Expand All @@ -196,7 +196,7 @@ def set_pull_request_groups(response):
set_env_and_output("PULL_REQUEST_URL", html_url)


@retry
@retry(attempts=5, timeout=30)
def list_pull_requests(target, source):
"""Given a target and source, return a list of pull requests that match
(or simply exit given some kind of error code)
Expand All @@ -219,9 +219,10 @@ def list_pull_requests(target, source):
return response.json()


@retry
@retry(attempts=5, timeout=30)
def add_assignees(entry, assignees):
"""Given a pull request metadata (from create or update) add assignees
"""
Given a pull request metadata (from create or update) add assignees
Parameters:
entry (dict) : the pull request metadata
Expand Down Expand Up @@ -250,7 +251,8 @@ def add_assignees(entry, assignees):


def find_pull_request(listing, source):
"""Given a listing and a source, find a pull request based on the source
"""
Given a listing and a source, find a pull request based on the source
(the branch name).
Parameters:
Expand All @@ -264,7 +266,7 @@ def find_pull_request(listing, source):
return entry


@retry
@retry(attempts=5, timeout=30)
def find_default_branch():
"""
Find default branch for a repo (only called if branch not provided)
Expand All @@ -282,7 +284,7 @@ def find_default_branch():
return default_branch


@retry
@retry(attempts=5, timeout=30)
def add_reviewers(entry, reviewers, team_reviewers):
"""
Given regular or team reviewers, add them to a PR.
Expand Down

0 comments on commit 89160a5

Please sign in to comment.