-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto-close and auto-run-pipline (#20516)
* release_iseus_status_auto_reply * issue_aoto_close_revert * Update main.py * Update main.py * Update update_issue_body.py * Update reply_generator.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update update_issue_body.py * Update main.py * Update reply_generator.py * Update main.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/update_issue_body.py * Update update_issue_body.py * Update main.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/main.py * Update main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/update_issue_body.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/update_issue_body.py * Update reply_generator.py * Update main.py * Update scripts/release_issue_status/update_issue_body.py Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Update scripts/release_issue_status/update_issue_body.py Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update main.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/main.py * Update main.py * Update reply_generator.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update main.py * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update main.py * Update reply_generator.py * Add files via upload * Update reply_generator.py * Update update_issue_body.py * Update reply_generator.py * Update auto_pipeline_run.py * Update auto_pipeline_run.py * add auto-close * Update release_issue_status.yml for Azure Pipelines * Update auto_close.py * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * fix bug * Update main.py * Update auto_close.py * Update auto_close.py * Update main.py * Update reply_generator.py * Update main.py * Update main.py * Update auto_close.py * Update main.py * Update auto-close * Update auto_pipeline_run.py * Update update_issue_body.py * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update auto_pipeline_run.py * Add pipeline link * Update pipeline link * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update requirement.txt * Update auto_pipeline_run.py * Add get_python_pipeline * Update auto_pipeline_run.py * test * test * add outputfolder * add label * Update main.py * Update get_python_pipeline.py * Update main.py * Update auto_pipeline_run.py Co-authored-by: Zed <601306339@qq.com> Co-authored-by: Zed Lei <59104634+RAY-316@users.noreply.github.com> Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
- Loading branch information
1 parent
acfb309
commit 53ea0c0
Showing
8 changed files
with
195 additions
and
34 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,36 @@ | ||
import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def auto_close_issue(sdk_repo, item): | ||
issue_number, package_name = item.issue_object.number, item.package | ||
issue_info = sdk_repo.get_issue(number=issue_number) | ||
issue_author = issue_info.user.login | ||
last_comment = list(issue_info.get_comments())[-1] | ||
last_comment_date = last_comment.created_at | ||
last_version, last_time = get_last_released_date(package_name) | ||
if last_time and last_time > last_comment_date: | ||
comment = f'Hi @{issue_author}, pypi link: https://pypi.org/project/{package_name}/{last_version}/' | ||
issue_info.create_comment(body=comment) | ||
issue_info.edit(state='closed') | ||
item.labels.append('auto-closed') | ||
item.issue_object.set_labels(*item.labels) | ||
print(f"issue number:{issue_number} has been closed!") | ||
|
||
|
||
def get_last_released_date(package_name): | ||
pypi_link = f'https://pypi.org/project/{package_name}/#history' | ||
res = requests.get(pypi_link) | ||
soup = BeautifulSoup(res.text, 'html.parser') | ||
# find top div from <div class="release-timeline"> | ||
try: | ||
package_info = soup.select('div[class="release-timeline"]')[0].find_all('div')[0] | ||
last_version_mix = package_info.find_all('p', class_="release__version")[0].contents[0] | ||
except IndexError as e: | ||
return '', '' | ||
last_version = last_version_mix.replace(' ', '').replace('\n', '') | ||
last_version_date_str = package_info.time.attrs['datetime'].split('+')[0] | ||
last_version_date = datetime.datetime.strptime(last_version_date_str, '%Y-%m-%dT%H:%M:%S') | ||
return last_version, last_version_date |
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,47 @@ | ||
import json | ||
import os | ||
import re | ||
from msrest.authentication import BasicAuthentication | ||
from azure.devops.v6_0.pipelines.pipelines_client import PipelinesClient | ||
from azure.devops.v6_0.pipelines import models | ||
import requests | ||
|
||
|
||
def run_pipeline(issue_link, sdk_issue_object, pipeline_url): | ||
paramaters = { | ||
"stages_to_skip": [], | ||
"resources": { | ||
"repositories": { | ||
"self": { | ||
"refName": "refs/heads/main" | ||
} | ||
} | ||
}, | ||
"variables": { | ||
"BASE_BRANCH": { | ||
"value": f"{sdk_issue_object.head.label}", | ||
"isSecret": False | ||
}, | ||
"ISSUE_LINK": { | ||
"value": f"{issue_link}", | ||
"isSecret": False | ||
}, | ||
"PIPELINE_LINK": { | ||
"value": f"{pipeline_url}", | ||
"isSecret": False | ||
} | ||
} | ||
} | ||
# Fill in with your personal access token and org URL | ||
personal_access_token = os.getenv('PIPELINE_TOKEN') | ||
organization_url = 'https://dev.azure.com/azure-sdk' | ||
|
||
# Create a connection to the org | ||
credentials = BasicAuthentication('', personal_access_token) | ||
run_parameters = models.RunPipelineParameters(**paramaters) | ||
client = PipelinesClient(base_url=organization_url, creds=credentials) | ||
result = client.run_pipeline(project='internal',pipeline_id=2500,run_parameters=run_parameters) | ||
if result.state == 'inProgress': | ||
return True | ||
else: | ||
return False |
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,27 @@ | ||
import os | ||
import re | ||
|
||
from msrest.authentication import BasicAuthentication | ||
from azure.devops.v6_0.pipelines.pipelines_client import PipelinesClient | ||
|
||
|
||
def get_python_pipelines(): | ||
python_piplines = {} | ||
pipeline_client = PipelinesClient(base_url='https://dev.azure.com/azure-sdk', | ||
creds=BasicAuthentication('', os.getenv('PIPELINE_TOKEN'))) | ||
pipelines = pipeline_client.list_pipelines(project='internal') | ||
for pipeline in pipelines: | ||
if re.findall('^python - \w*$', pipeline.name): | ||
key = pipeline.name.replace('python - ', '') | ||
python_piplines[key] = pipeline.id | ||
return python_piplines | ||
|
||
|
||
def get_pipeline_url(python_piplines, output_folder): | ||
definitionId = python_piplines.get(output_folder) | ||
if definitionId: | ||
pipeline_url = 'https://dev.azure.com/azure-sdk/internal/_build?definitionId={}'.format(definitionId) | ||
else: | ||
print('Cannot find definitionId, Do not display pipeline_url') | ||
pipeline_url = '' | ||
return pipeline_url |
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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
PyGithub | ||
datetime | ||
azure.storage.blob==12.8.1 | ||
requests | ||
bs4 | ||
azure.storage.blob==12.8.1 | ||
azure-devops | ||
msrest |
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