Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging on GitHub API errors #1408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions alibot_helpers/github_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ def post(self, url, data, stable_api=True, **kwds):
data = json.dumps(data) if type(data) == dict else data
response = requests.post(url=url, data=data, headers=headers)
sc = response.status_code
if sc == 422:
try:
res = response.json()
print(f"GitHub error: Unprocessable Entity: {res}", file=sys.stderr)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to print the HTTP response output here? I think it shouldn't have any confidential info but I'm not 100% sure

except:
print(f"GitHub error: Unprocessable Entity", file=sys.stderr)
return sc

@trace
Expand Down
5 changes: 3 additions & 2 deletions report-pr-errors
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def get_pending_namespace(args):
url="")


def handle_branch(cgh, pr, logs, args):
def handle_branch(cgh: GithubCachedClient, pr, logs, args):
ns = get_pending_namespace(args) if args.pending else \
Namespace(commit=args.pr,
status=args.status + "/error",
Expand All @@ -477,7 +477,7 @@ def handle_branch(cgh, pr, logs, args):
sys.exit(0)


def handle_pr_id(cgh, pr, logs, args):
def handle_pr_id(cgh: GithubCachedClient, pr, logs, args):
commit = cgh.get("/repos/{repo_name}/commits/{ref}",
repo_name=pr.repo_name,
ref=pr.commit)
Expand Down Expand Up @@ -538,6 +538,7 @@ def handle_pr_id(cgh, pr, logs, args):
)



def parse_pr(pr):
repo_name, pr_id, pr_commit = parseGithubRef(pr)
return Namespace(repo_name=repo_name,
Expand Down