-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[EngSys] added to python script to not fail if there is an existing PR #18397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,10 @@ | |
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import argparse | ||
| import os | ||
| import logging | ||
| import sys | ||
| import json | ||
| import os | ||
| import requests | ||
|
|
||
| from common_tasks import run_check_call | ||
|
|
||
|
|
@@ -54,7 +55,31 @@ def find_swagger_folders(directory): | |
| return ret | ||
|
|
||
|
|
||
| def check_diff(folder): | ||
| def check_for_open_pr(service_directory): | ||
| # Return True if there is an OPEN PR of the format ""Automated autorest generation for {service_directory}"" | ||
| # Return False otherwise | ||
|
|
||
| pr_title = "Automated autorest generation for {}".format(service_directory) | ||
|
|
||
| page_size = 50 | ||
| page_number = 1 | ||
| request_url = "https://api.github.com/repos/Azure/azure-sdk-for-python/pulls?state=open&per_page={}&page={}" | ||
|
|
||
| s = requests.session() | ||
| response = s.get(request_url.format(page_size, page_number)) | ||
| while "next" in response.links: | ||
| body = response.content.decode("utf-8") | ||
| body = json.loads(body) | ||
| for link in body: | ||
| if link["title"] == pr_title: | ||
| return True | ||
|
|
||
| next_page = response.links["next"]["url"] | ||
| response = s.get(next_page) | ||
| return False | ||
|
|
||
|
|
||
| def check_diff(folder, service_dir): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar you shouldn't need to manually do a git diff. See https://github.com/Azure/azure-sdk-for-python/blob/master/eng/common/pipelines/templates/steps/git-push-changes.yml#L18
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The git diff is for users to be able to inspect which files are different in the pipeline on a failure.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK if that is interesting for other cases that is fine. However I'd encourage you to do those type of command line calls inline script blocks in the yml file, unless you feel folks would want to run them locally as well. This is perhaps my preference for using a shell scripting language (script/bash/pwsh) when running command line tools as opposed to wrapping them in process calls in a higher level language like python. Just something to keep in mind not something that is necessarily actionable. :) |
||
| # We don't care about changes to txt files (dev_requirements change) | ||
| run_check_call(["git", "status"], sdk_dir, always_exit=False) | ||
|
|
||
|
|
@@ -87,9 +112,10 @@ def check_diff(folder): | |
| if result: | ||
| command = ["git", "status"] | ||
| run_check_call(command, root_dir) | ||
| raise ValueError( | ||
| "Found difference between re-generated code and current commit. Please re-generate with the latest autorest." | ||
| ) | ||
| if not check_for_open_pr(service_dir): | ||
| raise ValueError( | ||
| "Found difference between re-generated code and current commit. Please re-generate with the latest autorest." | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
@@ -105,4 +131,4 @@ def check_diff(folder): | |
|
|
||
| if len(folders): | ||
| for folder in folders: | ||
| check_diff(folder) | ||
| check_diff(folder, args.service_directory) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to do this if your branch name is consistent. As the create-pull-request template will not create an additional PR against a given branch if one already exists. That is how we generally handle this case in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is great to know, I can close this PR entirely then