-
Notifications
You must be signed in to change notification settings - Fork 4
/
docs_cherry_pick.py
98 lines (73 loc) · 2.28 KB
/
docs_cherry_pick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
To ge files from LFS to apply patch use `git add --renormalize .`
"""
import argparse
import os
import urllib.request
from pathlib import Path
from git import Repo
from tqdm import tqdm
from release_utils import (
PR_NUM_PATTERN,
REPO_DIR_NAME,
get_milestone,
iter_pull_request,
setup_cache,
)
parser = argparse.ArgumentParser()
parser.add_argument('milestone', help='The milestone to list')
parser.add_argument(
'--first-commits', help='file with list of first commits to cherry pick'
)
parser.add_argument(
'--stop-after', help='Stop after this commit', default=0, type=int
)
parser.add_argument(
'--git-repository',
help='The git repository',
default=os.environ.get(
'GIT_RELEASE_REPOSITORY', '[email protected]:napari/napari.git'
),
)
parser.add_argument(
'--git-main-branch',
help='The git main branch',
default=os.environ.get('GIT_RELEASE_MAIN_BRANCH', 'main'),
)
def get_consumed_pr():
res = set()
base = repo.merge_base(f'docs_{milestone.title}', f'v{milestone.title}x')
for commit in repo.iter_commits(
f'{base[0].binsha.hex()}..docs_{milestone.title}'
):
if (match := PR_NUM_PATTERN.search(commit.message)) is not None:
pr_num = int(match[1])
res.add(pr_num)
return res
LOCAL_DIR = Path(__file__).parent.absolute()
args = parser.parse_args()
setup_cache()
milestone = get_milestone(args.milestone)
if not (LOCAL_DIR / 'patch_dir').exists():
(LOCAL_DIR / 'patch_dir').mkdir()
patch_dir_path = LOCAL_DIR / 'patch_dir' / f'docs_{milestone.title}'
if not patch_dir_path.exists():
patch_dir_path.mkdir()
repo = Repo(LOCAL_DIR / REPO_DIR_NAME)
repo.git.checkout(f'docs_{milestone.title}')
pr_list_base = sorted(
iter_pull_request(f'milestone:{args.milestone} is:merged', repo='docs'),
key=lambda x: x.closed_at,
)
skip_pr = {58, 106, 149, 151, 181, 175} | get_consumed_pr()
for pull in tqdm(pr_list_base):
patch_file = patch_dir_path / f'{pull.number}.patch'
if pull.number in skip_pr:
continue
print(pull.number, pull.title)
if not patch_file.exists():
urllib.request.urlretrieve(
f'https://github.com/napari/docs/commit/{pull.merge_commit_sha}.patch',
patch_file,
)
repo.git.am(str(patch_file))