Skip to content

Commit 433d592

Browse files
authored
Merge fixes scripts for validate pr description and update changelog to stable-25-1 (#16028)
1 parent ddd89a2 commit 433d592

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

.github/actions/update_changelog/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ runs:
4040
run: |
4141
git config --local user.email "action@github.com"
4242
git config --local user.name "GitHub Action"
43-
git config --local github.token ${{ env.UPDATE_REPO_TOKEN }}
43+
git config --local github.token ${{ env.GH_TOKEN }}
4444
python ${{ github.action_path }}/update_changelog.py pr_data.txt "${{ inputs.changelog_path }}" "${{ inputs.base_branch }}" "${{ inputs.suffix }}"

.github/actions/update_changelog/update_changelog.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
CATEGORY_PREFIX = "### "
1616
ITEM_PREFIX = "* "
1717

18+
GH_TOKEN = os.getenv("GH_TOKEN")
19+
1820
@functools.cache
1921
def get_github_api_url():
2022
return os.getenv('GITHUB_REPOSITORY')
@@ -121,7 +123,8 @@ def update_changelog(changelog_path, pr_data):
121123
if validate_pr_description(pr["body"], is_not_for_cl_valid=False):
122124
category = extract_changelog_category(pr["body"])
123125
category = match_pr_to_changelog_category(category)
124-
body = extract_changelog_body(pr["body"])
126+
dirty_body = extract_changelog_body(pr["body"])
127+
body = dirty_body.replace("\r", "")
125128
if category and body:
126129
body += f" [#{pr['number']}]({pr['url']})"
127130
body += f" ([{pr['name']}]({pr['user_url']}))"
@@ -150,7 +153,7 @@ def fetch_pr_details(pr_id):
150153
url = f"https://api.github.com/repos/{get_github_api_url()}/pulls/{pr_id}"
151154
headers = {
152155
"Accept": "application/vnd.github.v3+json",
153-
"Authorization": f"token {GITHUB_TOKEN}"
156+
"Authorization": f"token {GH_TOKEN}"
154157
}
155158
response = requests.get(url, headers=headers)
156159
response.raise_for_status()
@@ -160,7 +163,7 @@ def fetch_user_details(username):
160163
url = f"https://api.github.com/users/{username}"
161164
headers = {
162165
"Accept": "application/vnd.github.v3+json",
163-
"Authorization": f"token {GITHUB_TOKEN}"
166+
"Authorization": f"token {GH_TOKEN}"
164167
}
165168
response = requests.get(url, headers=headers)
166169
response.raise_for_status()
@@ -175,8 +178,6 @@ def fetch_user_details(username):
175178
changelog_path = sys.argv[2]
176179
base_branch = sys.argv[3]
177180
suffix = sys.argv[4]
178-
179-
GITHUB_TOKEN = os.getenv("UPDATE_REPO_TOKEN")
180181

181182
try:
182183
with open(pr_data_file, 'r') as file:
@@ -190,12 +191,13 @@ def fetch_user_details(username):
190191
try:
191192
pr_details = fetch_pr_details(pr["id"])
192193
user_details = fetch_user_details(pr_details["user"]["login"])
194+
name = user_details.get("name", None)
193195
if validate_pr_description(pr_details["body"], is_not_for_cl_valid=False):
194196
pr_data.append({
195197
"number": pr_details["number"],
196198
"body": pr_details["body"].strip(),
197199
"url": pr_details["html_url"],
198-
"name": user_details.get("name", pr_details["user"]["login"]), # Use login if name is not available
200+
"name": name or pr_details["user"]["login"], # Use login if name is not available
199201
"user_url": pr_details["user"]["html_url"]
200202
})
201203
except Exception as e:
@@ -204,7 +206,7 @@ def fetch_user_details(username):
204206

205207
update_changelog(changelog_path, pr_data)
206208

207-
base_branch_name = f"changelog-for-{base_branch}-{suffix}"
209+
base_branch_name = f"changelog/{base_branch}-{suffix}"
208210
branch_name = base_branch_name
209211
index = 1
210212
while branch_exists(branch_name):

.github/workflows/update_changelog.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
default: "changelog-for-"
2323

2424
env:
25-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
GH_TOKEN: ${{ secrets.YDBOT_TOKEN }}
2626

2727
jobs:
2828
gather-prs:
@@ -39,7 +39,6 @@ jobs:
3939
TYPE="${{ github.event.inputs.type }}"
4040
START="${{ github.event.inputs.start }}"
4141
BRANCH="${GITHUB_REF_NAME}"
42-
4342
echo "::notice:: branch = ${GITHUB_REF_NAME}, start = $START"
4443
4544
if [ "$TYPE" == "date" ]; then
@@ -86,7 +85,7 @@ jobs:
8685
- name: Update Changelog
8786
uses: ./.github/actions/update_changelog
8887
env:
89-
UPDATE_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
GH_TOKEN: ${{ secrets.YDBOT_TOKEN }}
9089
with:
9190
pr_data: "${{ needs.gather-prs.outputs.prs }}"
9291
changelog_path: "${{ github.event.inputs.changelog_path }}"

.github/workflows/validate_pr_description.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
branches:
1010
- main
11+
- stable-*
1112

1213
jobs:
1314
validate-pr-description:
@@ -16,6 +17,8 @@ jobs:
1617
steps:
1718
- name: Check out the repository
1819
uses: actions/checkout@v4
20+
with:
21+
ref: main
1922

2023
- name: Use custom PR validation action
2124
id: validate

.github/workflows/weekly_update_changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- stable-*
99
workflow_dispatch:
1010
env:
11-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
GH_TOKEN: ${{ secrets.YDBOT_TOKEN }}
1212

1313
jobs:
1414
gather-prs:
@@ -63,7 +63,7 @@ jobs:
6363
- name: Update Changelog
6464
uses: ./.github/actions/update_changelog
6565
env:
66-
UPDATE_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
GH_TOKEN: ${{ secrets.YDBOT_TOKEN }}
6767
with:
6868
pr_data: "${{ needs.gather-prs.outputs.prs }}"
6969
changelog_path: "./CHANGELOG.md" # RODO: Use the correct path to your CHANGELOG.md file

0 commit comments

Comments
 (0)