Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
453 commits
Select commit Hold shift + click to select a range
5218195
testing-11
Pavank1992 Jun 22, 2023
24dd4d9
Testing
iancha1992 Jun 22, 2023
a07b183
testing-12
Pavank1992 Jun 22, 2023
148a7a3
Testing
iancha1992 Jun 22, 2023
552a86e
Testing
iancha1992 Jun 22, 2023
b9e16f3
testing-13
Pavank1992 Jun 22, 2023
b92bd2a
testing
iancha1992 Jun 22, 2023
8816bd8
Testing
iancha1992 Jun 22, 2023
14b0c0b
remove the exposed token
iancha1992 Jun 22, 2023
756c32e
Testing
iancha1992 Jun 22, 2023
38e61f5
Deleted the index.js file
iancha1992 Jun 22, 2023
5d76467
Testing
iancha1992 Jun 22, 2023
824fc08
Testing
iancha1992 Jun 23, 2023
f611c2b
Testing
iancha1992 Jun 23, 2023
88c6b08
Testing
iancha1992 Jun 23, 2023
20ed3ab
Testing
iancha1992 Jun 23, 2023
baa329e
Testing
iancha1992 Jun 23, 2023
c6f9b06
Testing
iancha1992 Jun 23, 2023
d9eec94
Testing
iancha1992 Jun 23, 2023
0e2616f
Testing
iancha1992 Jun 23, 2023
178276f
Testing
iancha1992 Jun 23, 2023
b483b5e
testing
iancha1992 Jun 25, 2023
36c292d
Testing
iancha1992 Jun 25, 2023
33eb795
Testing
iancha1992 Jun 25, 2023
df20d4b
Testing
iancha1992 Jun 25, 2023
b21d4cc
Testing
iancha1992 Jun 25, 2023
6aa71eb
Testing
iancha1992 Jun 25, 2023
8bbfd6d
Testing
iancha1992 Jun 25, 2023
5e803f6
Testing
iancha1992 Jun 25, 2023
d708f09
Testing
iancha1992 Jun 25, 2023
86b164d
Testing
iancha1992 Jun 25, 2023
cccba6b
Testing
iancha1992 Jun 25, 2023
bb25d6d
Testing
iancha1992 Jun 25, 2023
39ea0e6
Testing
iancha1992 Jun 25, 2023
b7451f5
testing
iancha1992 Jun 25, 2023
63bbcfb
Testing
iancha1992 Jun 25, 2023
22f634d
Testing
iancha1992 Jun 25, 2023
8c6cacb
Testing
iancha1992 Jun 25, 2023
2c71f4f
Testing
iancha1992 Jun 26, 2023
998b81d
Testing
iancha1992 Jun 26, 2023
003ae52
Testing
iancha1992 Jun 26, 2023
fa274f2
Testing
iancha1992 Jun 26, 2023
718b469
Testing
iancha1992 Jun 26, 2023
1dac5de
Testing
iancha1992 Jun 26, 2023
c32adac
Testing
iancha1992 Jun 26, 2023
1b6f84d
Testing
iancha1992 Jun 26, 2023
e1dcbc1
Testing
iancha1992 Jun 26, 2023
06558ff
Testing
iancha1992 Jun 26, 2023
6c6be7b
Testing
iancha1992 Jun 26, 2023
df9664b
Testing
iancha1992 Jun 26, 2023
8f9fc2c
Testing
iancha1992 Jun 26, 2023
df476c8
Testing
iancha1992 Jun 27, 2023
db1b60d
Testing
iancha1992 Jun 27, 2023
a1ed0ca
Testing
iancha1992 Jun 27, 2023
d9c00d3
Testing
iancha1992 Jun 27, 2023
3b744b8
Testing
iancha1992 Jun 27, 2023
ad8d06c
testing
iancha1992 Jun 27, 2023
9f6eedc
Testing
iancha1992 Jun 29, 2023
15a78a1
Testing
iancha1992 Jun 29, 2023
d81dbf2
Testing
iancha1992 Jun 29, 2023
337b28e
Testing
iancha1992 Jun 29, 2023
a218c94
adding create PR
Pavank1992 Jun 30, 2023
56e19d4
testing
iancha1992 Jun 30, 2023
4f06c66
Testing
iancha1992 Jun 30, 2023
c7c14fa
Testing
iancha1992 Jun 30, 2023
459b470
Testing
iancha1992 Jun 30, 2023
e286723
Testing
iancha1992 Jun 30, 2023
2d23933
testing
iancha1992 Jul 5, 2023
0f3a1b6
Testing
iancha1992 Jul 5, 2023
23db2d8
Testing
iancha1992 Jul 5, 2023
702c9d7
testing
iancha1992 Jul 5, 2023
f494a83
Testing
iancha1992 Jul 5, 2023
cc3fe7b
testing
iancha1992 Jul 5, 2023
e0ef338
testing
iancha1992 Jul 5, 2023
aef7be5
Testing
iancha1992 Jul 5, 2023
65a1005
testing
iancha1992 Jul 5, 2023
f554942
Testing
iancha1992 Jul 5, 2023
b04b267
testing
iancha1992 Jul 6, 2023
6dc22ee
Testing
iancha1992 Jul 6, 2023
4381f02
Testing
iancha1992 Jul 6, 2023
e1478a8
Testing
iancha1992 Jul 6, 2023
4961247
testing
iancha1992 Jul 6, 2023
9dde01d
Testing
iancha1992 Jul 6, 2023
e4082cd
testing
iancha1992 Jul 6, 2023
ac42957
Testing
iancha1992 Jul 6, 2023
a2aa2d0
Testing
iancha1992 Jul 6, 2023
d0a63ec
testing
iancha1992 Jul 7, 2023
09578cb
Testing
iancha1992 Jul 7, 2023
b790059
Testing
iancha1992 Jul 7, 2023
e6619cf
testing
iancha1992 Jul 7, 2023
6cdb085
Testing
iancha1992 Jul 7, 2023
5057605
Testing
iancha1992 Jul 7, 2023
cfed87a
Testing
iancha1992 Jul 7, 2023
c84e08d
testing
iancha1992 Jul 9, 2023
0564aac
Testing
iancha1992 Jul 10, 2023
d6c9939
testing
iancha1992 Jul 10, 2023
33059d6
Testing
iancha1992 Jul 10, 2023
4f3074d
Testing
iancha1992 Jul 10, 2023
55fa676
Testing
iancha1992 Jul 11, 2023
650cb4c
Testing
iancha1992 Jul 14, 2023
5c47b32
Testing
iancha1992 Jul 14, 2023
d938683
Testing
iancha1992 Jul 14, 2023
b74c494
Testing
iancha1992 Jul 14, 2023
6396a5b
Testing
iancha1992 Jul 17, 2023
6468fc7
Testing
iancha1992 Jul 17, 2023
166f316
Testing
iancha1992 Jul 17, 2023
ecd990b
Testing
iancha1992 Jul 17, 2023
d946982
Testing
iancha1992 Jul 17, 2023
90278d8
Testing
iancha1992 Jul 17, 2023
425656d
Testing
iancha1992 Jul 17, 2023
0204a7e
Testing
iancha1992 Jul 17, 2023
a79ed82
Testing
iancha1992 Jul 17, 2023
55ac332
Testing
iancha1992 Jul 17, 2023
8a05a18
Testing
iancha1992 Jul 17, 2023
e414e50
Testing
iancha1992 Jul 17, 2023
7adbff1
Testing
iancha1992 Jul 17, 2023
31b6c1a
Testing
iancha1992 Jul 17, 2023
7eaebcc
Testing
iancha1992 Jul 17, 2023
9b8aba6
Testing
iancha1992 Jul 17, 2023
4a38b34
Testing
iancha1992 Jul 17, 2023
4bbc013
Testing
iancha1992 Jul 19, 2023
a0b07b7
Testing
iancha1992 Jul 19, 2023
aef0812
Testing
iancha1992 Jul 19, 2023
afdfbb0
Testing
iancha1992 Jul 19, 2023
97b50f5
start
iancha1992 Jul 19, 2023
08a6dff
Testing
iancha1992 Jul 19, 2023
9501251
Testing
iancha1992 Jul 19, 2023
eeafd5c
Testing
iancha1992 Jul 20, 2023
0a191bc
Testing
iancha1992 Jul 20, 2023
fea7414
Testing
iancha1992 Jul 26, 2023
b6722dc
Testing
iancha1992 Jul 26, 2023
75cb214
Testing
iancha1992 Jul 26, 2023
b38b80f
Testing
iancha1992 Jul 26, 2023
94dca01
fix
iancha1992 Jul 26, 2023
9ef1afd
Testing
iancha1992 Jul 26, 2023
dd3f823
testing
iancha1992 Jul 26, 2023
8fa57fd
Testing
iancha1992 Jul 26, 2023
0b3f6e3
Testing
iancha1992 Jul 26, 2023
4b548c4
Testing
iancha1992 Jul 26, 2023
83f28fe
Testing
iancha1992 Jul 26, 2023
d2bbc6b
Testing
iancha1992 Jul 27, 2023
ee71105
testing
iancha1992 Jul 27, 2023
7eb41bd
Testing
iancha1992 Jul 27, 2023
2867d41
Testing
iancha1992 Jul 27, 2023
4443cd5
Testing
iancha1992 Jul 27, 2023
a12cdfd
Testing
iancha1992 Jul 27, 2023
1607453
Testing
iancha1992 Jul 27, 2023
c7109a6
Testing
iancha1992 Jul 27, 2023
dd94c7b
Testing
iancha1992 Jul 27, 2023
9215b83
Testing
iancha1992 Jul 27, 2023
7523554
Testing
iancha1992 Jul 27, 2023
ef3c2cf
Testing
iancha1992 Jul 27, 2023
472426b
Testing
iancha1992 Jul 27, 2023
b3cc0e2
Testing
iancha1992 Jul 27, 2023
20beb87
Testing
iancha1992 Jul 28, 2023
15db124
Testing
iancha1992 Jul 28, 2023
e013e38
testing
iancha1992 Jul 28, 2023
82236ab
Testing
iancha1992 Jul 28, 2023
87631c1
Testing
iancha1992 Jul 28, 2023
9a68f52
Testing
iancha1992 Jul 28, 2023
bc47e56
Testing
iancha1992 Jul 28, 2023
0ab76fd
Testing
iancha1992 Jul 28, 2023
699d87a
Testing
iancha1992 Jul 28, 2023
21e90b3
Testing
iancha1992 Jul 28, 2023
1c6bbed
Testing
iancha1992 Jul 28, 2023
905243b
Testing:
iancha1992 Jul 31, 2023
e1bb22c
Testing
iancha1992 Jul 31, 2023
cc0c3a2
Testing
iancha1992 Jul 31, 2023
dca61fe
testing
iancha1992 Jul 31, 2023
cd8fcf5
Testing
iancha1992 Jul 31, 2023
cf8427e
Testing
iancha1992 Jul 31, 2023
f20b7ec
Testing
iancha1992 Jul 31, 2023
30fa65f
Testing
iancha1992 Jul 31, 2023
1850085
Testing
iancha1992 Aug 1, 2023
0e9b276
Testing
iancha1992 Aug 1, 2023
213544a
Testing
iancha1992 Aug 1, 2023
72b85be
Testing
iancha1992 Aug 1, 2023
bc69fe5
Testing
iancha1992 Aug 2, 2023
84ba209
Testing
iancha1992 Aug 3, 2023
05133b9
Testing
iancha1992 Aug 3, 2023
8a3c2b9
Testing
iancha1992 Aug 3, 2023
5be5475
Testing
iancha1992 Aug 3, 2023
66a6df6
Testing
iancha1992 Aug 3, 2023
1ef0344
Testing
iancha1992 Aug 3, 2023
73f442e
Testing
iancha1992 Aug 3, 2023
2ecc328
Testing
iancha1992 Aug 3, 2023
fe592f7
Testing
iancha1992 Aug 3, 2023
be32de5
Testing
iancha1992 Aug 3, 2023
a2534fc
Testing
iancha1992 Aug 3, 2023
de4c0bb
Testing
iancha1992 Aug 3, 2023
053d92b
Testing
iancha1992 Aug 3, 2023
b178769
Testing
iancha1992 Aug 3, 2023
5a78bd6
Testing
iancha1992 Aug 3, 2023
1f9ea55
Testing
iancha1992 Aug 4, 2023
1c77f37
Testing
iancha1992 Aug 4, 2023
3effc21
Testing
iancha1992 Aug 4, 2023
8df767d
Testing
iancha1992 Aug 4, 2023
cd9fad8
Testing
iancha1992 Aug 4, 2023
27ec7d9
Testing
iancha1992 Aug 4, 2023
ee4db9c
Testing
iancha1992 Aug 4, 2023
09b2799
Testing
iancha1992 Aug 4, 2023
9d0fcfc
Testing
iancha1992 Aug 4, 2023
8c3743a
Testing
iancha1992 Aug 4, 2023
8dff65d
Testing
iancha1992 Aug 7, 2023
5752516
Testing
iancha1992 Aug 7, 2023
1f5336d
Testing
iancha1992 Aug 7, 2023
7975159
Testing
iancha1992 Aug 8, 2023
59d94e6
Testing
iancha1992 Aug 8, 2023
29763d5
Testing
iancha1992 Aug 8, 2023
bcd39de
Testing
iancha1992 Aug 8, 2023
633ee5b
Testing
iancha1992 Aug 8, 2023
2ddcb82
Testing
iancha1992 Aug 8, 2023
45a22ad
Testing
iancha1992 Aug 8, 2023
0a33882
Testing
iancha1992 Aug 10, 2023
b25b0c1
Testing
iancha1992 Aug 10, 2023
07b3676
Testing
iancha1992 Aug 10, 2023
4dd26fb
Testing
iancha1992 Aug 10, 2023
e4c067a
Testing
iancha1992 Aug 10, 2023
ee68bbf
Testing
iancha1992 Aug 10, 2023
fee0e29
Testing
iancha1992 Aug 10, 2023
7a16fbb
Testing
iancha1992 Aug 10, 2023
12a6400
Testing
iancha1992 Aug 10, 2023
a73869a
Testing
iancha1992 Aug 14, 2023
44fb040
Testing
iancha1992 Aug 14, 2023
2ed2c0e
Testing
iancha1992 Aug 14, 2023
b6a71a1
Testing
iancha1992 Aug 14, 2023
1976847
Testing
iancha1992 Aug 21, 2023
02d8aac
Testing
iancha1992 Aug 21, 2023
372e235
Testing
iancha1992 Aug 21, 2023
cfab63a
Testing
iancha1992 Aug 21, 2023
5b414ae
Testing
iancha1992 Aug 21, 2023
44fa675
Testing
iancha1992 Aug 21, 2023
321e8ac
Testing
iancha1992 Aug 21, 2023
3662838
testing
iancha1992 Aug 22, 2023
be0eb2c
Testing
iancha1992 Aug 22, 2023
a4a1c76
Testing
iancha1992 Aug 22, 2023
926549e
Testing
iancha1992 Aug 22, 2023
9c07759
Testing
iancha1992 Aug 22, 2023
55aa173
Testing
iancha1992 Aug 22, 2023
f715ad4
Testing
iancha1992 Aug 22, 2023
4042491
Testing
iancha1992 Aug 22, 2023
cea4b3e
Testing
iancha1992 Aug 22, 2023
8a56335
Testing
iancha1992 Aug 22, 2023
a697b55
Testing
iancha1992 Aug 22, 2023
afb67b8
Testing
iancha1992 Aug 22, 2023
8d9e451
Testing
iancha1992 Aug 22, 2023
95236d8
Testing
iancha1992 Aug 22, 2023
15cb3e1
Testing
iancha1992 Aug 22, 2023
0741da1
Testing
iancha1992 Aug 22, 2023
3dc3642
Testing
iancha1992 Aug 22, 2023
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
42 changes: 42 additions & 0 deletions actions/cherry-picker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'Cherry-picker when comment is created or issue/pr is closed'
description: 'Cherry-picks the commit'
inputs:
triggered-on:
required: true
default: ${{ github.triggered-on }}
pr-number:
required: true
default: ${{ github.pr-number }}
milestone-title:
required: false
default: ${{ github.milestone-title }}
milestoned-issue-number:
required: false
default: ${{ github.milestoned-issue-number }}
is-prod:
required: true
default: ${{ github.is-prod }}
runs:
using: 'composite'
steps:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Dependencies
run: |
pip install -r ${{ github.action_path }}/requirements.txt
shell: bash
- name: Pass Inputs to Shell
run: |
echo "INPUT_TRIGGERED_ON=${{ inputs.triggered-on }}" >> $GITHUB_ENV
echo "INPUT_PR_NUMBER=${{ inputs.pr-number }}" >> $GITHUB_ENV
echo "INPUT_MILESTONE_TITLE=${{ inputs.milestone-title }}" >> $GITHUB_ENV
echo "INPUT_MILESTONED_ISSUE_NUMBER=${{ inputs.milestoned-issue-number }}" >> $GITHUB_ENV
echo "INPUT_IS_PROD=${{ inputs.is-prod }}" >> $GITHUB_ENV
shell: bash
- name: Run python index.py
run: |
chmod +x ${{ github.action_path }}/index.py
python -u ${{ github.action_path }}/index.py
shell: bash
174 changes: 174 additions & 0 deletions actions/cherry-picker/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import os, subprocess, requests
from pprint import pprint

headers = {
'X-GitHub-Api-Version': '2022-11-28'
}
token = os.environ["GH_TOKEN"]
upstream_url = "https://github.com/bazelbuild/bazel.git"
upstream_repo = upstream_url.replace("https://github.com/", "").replace(".git", "")

def get_commit_id(pr_number, actor_name, action_event, api_repo_name):
params = {"per_page": 100}
response = requests.get(f'https://api.github.com/repos/{api_repo_name}/issues/{pr_number}/events', headers=headers, params=params)
commit_id = None
for event in response.json():
if (event["actor"]["login"] in actor_name) and (event["commit_id"] != None) and (commit_id == None) and (event["event"] == action_event):
commit_id = event["commit_id"]
elif (event["actor"]["login"] in actor_name) and (event["commit_id"] != None) and (commit_id != None) and (event["event"] == action_event):
raise Exception(f'PR#{pr_number} has multiple commits made by {actor_name}')
if commit_id == None: raise Exception(f'PR#{pr_number} has NO commit made by {actor_name}')
return commit_id

def get_reviewers(pr_number, api_repo_name, issues_data):
if "pull_request" not in issues_data: return []
r = requests.get(f'https://api.github.com/repos/{api_repo_name}/pulls/{pr_number}/reviews', headers=headers)
if len(r.json()) == 0: raise Exception(f"PR#{pr_number} has no approver at all.")
approvers_list = []
for review in r.json():
if review["state"] == "APPROVED": approvers_list.append(review["user"]["login"])
if len(approvers_list) == 0: raise Exception(f"PR#{pr_number} has no approval from the approver(s).")
return approvers_list

def extract_release_numbers_data(pr_number, api_repo_name):

def get_milestoned_issues(milestones, pr_number):
results= {}
for milestone in milestones:
params = {
"milestone": milestone["number"]
}
r = requests.get(f'https://api.github.com/repos/{api_repo_name}/issues', headers=headers, params=params)
for issue in r.json():
if issue["body"] == f'Forked from #{pr_number}' and issue["state"] == "open":
results[milestone["title"]] = issue["number"]
break
return results

response_milestones = requests.get(f'https://api.github.com/repos/{api_repo_name}/milestones', headers=headers)
all_milestones = list(map(lambda n: {"title": n["title"].split("release blockers")[0].replace(" ", ""), "number": n["number"]}, response_milestones.json()))
milestoned_issues = get_milestoned_issues(all_milestones, pr_number)
return milestoned_issues

def issue_comment(issue_number, body_content, api_repo_name, is_prod):
if is_prod == True:
subprocess.run(['git', 'remote', 'add', 'upstream', upstream_url])
subprocess.run(['gh', 'repo', 'set-default', upstream_repo])
subprocess.run(['gh', 'issue', 'comment', str(issue_number), '--body', body_content])
subprocess.run(['git', 'remote', 'rm', 'upstream'])
subprocess.run(['gh', 'repo', 'set-default', api_repo_name])
else:
subprocess.run(['gh', 'issue', 'comment', str(issue_number), '--body', body_content])

def cherry_pick(commit_id, release_branch_name, target_branch_name, issue_number, is_first_time, input_data):
gh_cli_repo_name = f"{input_data['user_name']}/bazel"
gh_cli_repo_url = f"git@github.com:{gh_cli_repo_name}.git"
master_branch = input_data["master_branch"]
user_name = input_data["user_name"]

def clone_and_sync_repo():
print("Cloning and syncing the repo...")
subprocess.run(['gh', 'repo', 'sync', gh_cli_repo_name, "-b", master_branch])
subprocess.run(['gh', 'repo', 'sync', gh_cli_repo_name, "-b", release_branch_name])
subprocess.run(['git', 'clone', f"https://{user_name}:{token}@github.com/{gh_cli_repo_name}.git"])
subprocess.run(['git', 'config', '--global', 'user.name', user_name])
subprocess.run(['git', 'config', '--global', 'user.email', input_data["email"]])
os.chdir("bazel")
subprocess.run(['git', 'remote', 'add', 'origin', gh_cli_repo_url])
subprocess.run(['git', 'remote', '-v'])

def checkout_release_number():
subprocess.run(['git', 'fetch', '--all'])
status_checkout_release = subprocess.run(['git', 'checkout', release_branch_name])

# Create the new release branch from the upstream if not exists already.
if status_checkout_release.returncode != 0:
print(f"There is NO branch called {release_branch_name}...")
print(f"Creating the {release_branch_name} from upstream, {upstream_url}")
subprocess.run(['git', 'remote', 'add', 'upstream', upstream_url])
subprocess.run(['git', 'remote', '-v'])
subprocess.run(['git', 'fetch', 'upstream'])
subprocess.run(['git', 'branch', release_branch_name, f"upstream/{release_branch_name}"])
release_push_status = subprocess.run(['git', 'push', '--set-upstream', 'origin', release_branch_name])
if release_push_status.returncode != 0:
raise Exception(f"Could not create and push the branch, {release_branch_name}")
subprocess.run(['git', 'remote', 'rm', 'upstream'])
subprocess.run(['git', 'checkout', release_branch_name])

status_checkout_target = subprocess.run(['git', 'checkout', '-b', target_branch_name])

# Need to let the user know that there is already a created branch with the same name and bazel-io needs to delete the branch
if status_checkout_target.returncode != 0:
# issue_comment(issue_number, f"Cherry-pick was being attempted. But, it failed due to already existent branch called {target_branch_name}\ncc: @bazelbuild/triage", input_data["api_repo_name"], input_data["is_prod"])
raise Exception(f"Cherry-pick was being attempted. But, it failed due to already existent branch called {target_branch_name}\ncc: @bazelbuild/triage")

def run_cherrypick():
print(f"Cherry-picking the commit id {commit_id} in CP branch: {target_branch_name}")
if input_data["is_prod"] == True:
cherrypick_status = subprocess.run(['git', 'cherry-pick', commit_id])
else:
cherrypick_status = subprocess.run(['git', 'cherry-pick', '-m', '1', commit_id])

if cherrypick_status.returncode == 0:
print(f"Successfully Cherry-picked, pushing it to branch: {target_branch_name}")
push_status = subprocess.run(['git', 'push', '--set-upstream', 'origin', target_branch_name])
if push_status.returncode != 0:
# issue_comment(issue_number, f"Cherry-pick was attempted, but failed to push. Please check if the branch, {target_branch_name}, already exists\ncc: @bazelbuild/triage", input_data["api_repo_name"], input_data["is_prod"])
raise Exception(f"Cherry-pick was attempted, but failed to push. Please check if the branch, {target_branch_name}, already exists\ncc: @bazelbuild/triage")
else:
# issue_comment(issue_number, "Cherry-pick was attempted but there were merge conflicts. Please resolve manually.\ncc: @bazelbuild/triage", input_data["api_repo_name"], input_data["is_prod"])
raise Exception("Cherry-pick was attempted but there were merge conflicts. Please resolve manually.\ncc: @bazelbuild/triage")

if is_first_time == True:
clone_and_sync_repo()
checkout_release_number()
run_cherrypick()

def create_pr(reviewers, release_number, issue_number, labels, issue_data, release_branch_name, target_branch_name, user_name, api_repo_name, is_prod):
def send_pr_msg(issue_number, head_branch, release_branch):
params = {
"head": head_branch,
"base": release_branch,
"state": "open"
}
r = requests.get(f'https://api.github.com/repos/{upstream_repo}/pulls', headers=headers, params=params).json()
if len(r) == 1:
cherry_picked_pr_number = r[0]["number"]
issue_comment(issue_number, f"Cherry-picked in https://github.com/{upstream_repo}/pull/{cherry_picked_pr_number}", api_repo_name, is_prod)
else:
issue_comment(issue_number, "Failed to send PR msg \ncc: @bazelbuild/triage", api_repo_name, is_prod)

head_branch = f"{user_name}:{target_branch_name}"
reviewers_str = ",".join(reviewers)
labels_str = ",".join(labels)
pr_title = f"[{release_number}] {issue_data['title']}"
pr_body = issue_data['body']
status_create_pr = subprocess.run(['gh', 'pr', 'create', "--repo", upstream_repo, "--title", pr_title, "--body", pr_body, "--head", head_branch, "--base", release_branch_name, '--label', labels_str, '--reviewer', reviewers_str])
if status_create_pr.returncode == 0:
send_pr_msg(issue_number, head_branch, release_branch_name)
else:
subprocess.run(['gh', 'issue', 'comment', str(issue_number), '--body', "PR failed to be created."])

def get_labels(pr_number, api_repo_name):
r = requests.get(f'https://api.github.com/repos/{api_repo_name}/issues/{pr_number}/labels', headers=headers)
labels_list = list(filter(lambda label: "area" in label or "team" in label, list(map(lambda x: x["name"], r.json()))))
if "awaiting-review" not in labels_list: labels_list.append("awaiting-review")
return labels_list

def get_pr_title_body(commit_id, api_repo_name, issue_data):
data = {}
data["title"] = issue_data["title"]
response_commit = requests.get(f"https://api.github.com/repos/{api_repo_name}/commits/{commit_id}")
original_msg = response_commit.json()["commit"]["message"]
pr_body = original_msg[original_msg.index("\n\n") + 2:] if "\n\n" in original_msg else original_msg
commit_str_body = f"Commit https://github.com/{api_repo_name}/commit/{commit_id}"

if "PiperOrigin-RevId" in pr_body:
piper_index = pr_body.index("PiperOrigin-RevId")
pr_body = pr_body[:piper_index] + f"{commit_str_body}\n\n" + pr_body[piper_index:]
else:
pr_body += f"\n\n{commit_str_body}"

data["body"] = pr_body
return data

75 changes: 75 additions & 0 deletions actions/cherry-picker/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os, requests
from functions import get_commit_id, get_reviewers, extract_release_numbers_data, cherry_pick, create_pr, get_labels, get_pr_title_body, issue_comment

triggered_on = os.environ["INPUT_TRIGGERED_ON"]
pr_number = os.environ["INPUT_PR_NUMBER"] if triggered_on == "closed" else os.environ["INPUT_PR_NUMBER"].split("#")[1]
milestone_title = os.environ["INPUT_MILESTONE_TITLE"]
milestoned_issue_number = os.environ["INPUT_MILESTONED_ISSUE_NUMBER"]
is_prod = os.environ["INPUT_IS_PROD"]

if is_prod == "true":
input_data = {
"is_prod": True,
"api_repo_name": "bazelbuild/bazel",
"master_branch": "master",
"release_branch_name_initials": "release-",
"user_name": "bazel-io",
"action_event": "closed",
"actor_name": {
"copybara-service[bot]"
},
"email": "bazel-io-bot@google.com"
}

else:
input_data = {
"is_prod": False,
"api_repo_name": "iancha1992/bazel",
"master_branch": "release_test",
"release_branch_name_initials": "fake-release-",
"user_name": "iancha1992",
"action_event": "merged",
"actor_name": {
"iancha1992",
"Pavank1992",
"chaheein123",
},
"email": "heec@google.com"
}

issue_data = requests.get(f"https://api.github.com/repos/{input_data['api_repo_name']}/issues/{pr_number}", headers={'X-GitHub-Api-Version': '2022-11-28'}).json()

# Check if the PR is closed.
if issue_data["state"] != "closed": raise ValueError(f'The PR #{pr_number} is not closed yet.')

# Retrieve commit_id. If the PR/issue has no commit or has multiple commits, then raise an error.
commit_id = get_commit_id(pr_number, input_data["actor_name"], input_data["action_event"], input_data["api_repo_name"])

# Retrieve approvers(reviewers) of the PR
reviewers = get_reviewers(pr_number, input_data["api_repo_name"], issue_data)

# Retrieve release_numbers
if triggered_on == "closed":
release_numbers_data = extract_release_numbers_data(pr_number, input_data["api_repo_name"])
elif triggered_on == "commented":
release_numbers_data = {milestone_title.split(" release blockers")[0]: milestoned_issue_number}

# Retrieve labels
labels = get_labels(pr_number, input_data["api_repo_name"])

# Retrieve issue/PR's title and body
pr_title_body = get_pr_title_body(commit_id, input_data["api_repo_name"], issue_data)

# Perform cherry-pick and then create a pr if it's successful.
is_first_time = True
for k in release_numbers_data.keys():
release_number = k
release_branch_name = f"{input_data['release_branch_name_initials']}{release_number}"
target_branch_name = f"cp{pr_number}-{release_number}"
issue_number = release_numbers_data[k]
try:
cherry_pick(commit_id, release_branch_name, target_branch_name, issue_number, is_first_time, input_data)
create_pr(reviewers, release_number, issue_number, labels, pr_title_body, release_branch_name, target_branch_name, input_data["user_name"], input_data["api_repo_name"], input_data["is_prod"])
except Exception as e:
issue_comment(issue_number, str(e), input_data["api_repo_name"], input_data["is_prod"])
is_first_time = False
3 changes: 3 additions & 0 deletions actions/cherry-picker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests==2.31.0
github3.py==4.0.1
PyGithub==1.58.2
Empty file added actions/cherry-picker/test.js
Empty file.
39 changes: 39 additions & 0 deletions actions/cherry-picker/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests, subprocess
from pprint import pprint

headers = {
'X-GitHub-Api-Version': '2022-11-28',
}



# git shortlog -s -n -e


# # url = 'https://api.github.com/repos/bazelbuild/bazel/issues/19173/comments'
# url = 'https://api.github.com/repos/bazelbuild/bazel/collaborators'

# url = "https://api.github.com/users/iancha1992/social_accounts"

# url = "https://api.github.com/users/iancha1992/social_accounts"

url = "https://api.github.com/users/haxorz/events/public"

# r = requests.get(url, headers=headers)


def taylor():
print("Taylor!!!")
raise Exception("hihihi")

try:
print("Hello world")
taylor()
print("Bye")

except Exception as e:
print("Except!!!!")
# print(e)
print("cherry", str(e))
print("cherry", str(e), "aaaa", "Cccc")
# print("cherry", type(str(e)))
4 changes: 4 additions & 0 deletions actions/release-helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ async function run() {
const owner = payload.repository.owner.login;
const repo = payload.repository.name;

console.log("This is payload!!!!!", payload)

if (command.startsWith("fork ")) {
// Check if the commenter is a collaborator of the repo
try {
Expand All @@ -23,13 +25,15 @@ async function run() {
repo,
username: payload.comment.user.login,
});
console.log("greatsuccess??")
} catch (err) {
await octokit.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: payload.comment.id,
content: '-1',
});
console.log("greatfailure??")
throw `user ${payload.comment.user.login} has no collaborator access in repo ${owner}/${repo}`;
}

Expand Down