mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 15:29:28 -05:00
Changelog fix 3rd way (#1259)
* init_commit_for_changelog_fix_2nd_way * 2nd_commit_for_changelog_fix_2nd_way * methods-3 * add_more_exception
This commit is contained in:
parent
006e4c9fce
commit
0c599f7d3a
70
.github/workflows/changelog.py
vendored
70
.github/workflows/changelog.py
vendored
@ -1,19 +1,50 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
raw_git = os.popen('git log next --since="24 hours" --pretty=format:"- %h - {USERNAME}*+%al-%an*: %s"').read()
|
main_repo_url = "https://github.com/eried/portapack-mayhem.git"
|
||||||
|
main_repo_identifier = "eried/portapack-mayhem"
|
||||||
|
# ^^&^ change these if main repo changed
|
||||||
|
|
||||||
|
os.system('gh repo set-default ' + main_repo_url)
|
||||||
|
|
||||||
|
raw_git = os.popen('git log next --since="1200 hours" --pretty=format:"- ^%h^ - {USERNAME}*_%al_%an*: %s"').read()
|
||||||
|
|
||||||
|
|
||||||
|
# ^ as github's rule, a real username can contains "-" but not "_" and "*", so use these two to seperate things.
|
||||||
|
# ^ during test at 2023-07-10, %al could return 3 different types of values:
|
||||||
|
# : 123+abc <<<< abc is real username
|
||||||
|
# : def <<<< def is 3rd level domain of unhidden email, drop this, fetch info from github cli client
|
||||||
|
# : note that github will probably change in the future
|
||||||
|
|
||||||
|
|
||||||
def compute_username(line):
|
def compute_username(line):
|
||||||
stripped = re.search(r'(?<=\*)(.*?)(?=\*)', line).group(0)
|
line_org = line
|
||||||
|
stripped = re.search(r'(?<=\*)(.*?)(?=\*)', line).group(0) # get the string between "*" and "*"
|
||||||
|
now_item_hash = re.search(r'(?<=\^)(.*?)(?=\^)', line).group(0) # get the string between "*" and "*"
|
||||||
|
stripped_org = stripped
|
||||||
|
stripped = re.search(r'(?<=\_)(.*?)(?=\_)', stripped).group(0) # get the string between "_" and "_"
|
||||||
|
stripped_fallback = stripped
|
||||||
|
# now it's like "123+abc" or "def"
|
||||||
|
|
||||||
|
if ("+" in stripped): # 123+abc
|
||||||
|
stripped = re.sub(r'^.*?\+', "", stripped)
|
||||||
|
elif not ("+" in stripped): # maybe not real username, dropped, fetch from github cli client
|
||||||
|
fetched_now_item_json = os.popen(
|
||||||
|
'gh search commits repo:' + main_repo_identifier + ' --json author --hash ' + now_item_hash).read()
|
||||||
|
stripped = extract_first_login(fetched_now_item_json)
|
||||||
|
if stripped is False: # 403
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
elif stripped == "app/": # user did their commit with github app
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
else: # exception and edge cases
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
|
||||||
|
if stripped is None: # if commit hash can't find AKA commit is only in fork
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
|
||||||
pattern = re.compile("[$@+&?].*[$@+&?]")
|
|
||||||
if pattern.match(stripped):
|
|
||||||
stripped = re.sub("[$@+&?].*[$@+&?]", "", stripped)
|
|
||||||
stripped = re.match(r'.+?(?=-)', stripped).group(0)
|
|
||||||
else:
|
|
||||||
stripped = re.sub(r'^.*?-', "", stripped)
|
|
||||||
return "@" + stripped
|
return "@" + stripped
|
||||||
|
|
||||||
|
|
||||||
@ -21,8 +52,31 @@ def compile_line(line):
|
|||||||
username = compute_username(line)
|
username = compute_username(line)
|
||||||
line = re.sub(r'[*].*[*]', "", line)
|
line = re.sub(r'[*].*[*]', "", line)
|
||||||
line = line.replace("{USERNAME}", username)
|
line = line.replace("{USERNAME}", username)
|
||||||
|
line = re.sub(r'\^', '', line, count=2)
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
def extract_first_login(json_data):
|
||||||
|
if not json_data: # if returned null
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(json_data)
|
||||||
|
|
||||||
|
if isinstance(data, list) and len(data) > 0:
|
||||||
|
first_object = data[0]
|
||||||
|
if 'author' in first_object and 'login' in first_object['author']:
|
||||||
|
return first_object['author']['login']
|
||||||
|
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.code == 403 and "API rate limit exceeded" in str(e):
|
||||||
|
return False
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
for row in raw_git.splitlines():
|
for row in raw_git.splitlines():
|
||||||
print(compile_line(row))
|
print(compile_line(row))
|
||||||
|
2
.github/workflows/create_nightly_release.yml
vendored
2
.github/workflows/create_nightly_release.yml
vendored
@ -63,6 +63,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-h1_h2-mayhem.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && zip -r sdcard.zip sdcard
|
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-h1_h2-mayhem.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && zip -r sdcard.zip sdcard
|
||||||
- name: Create changelog
|
- name: Create changelog
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
CHANGELOG=$(python3 .github/workflows/changelog.py)
|
CHANGELOG=$(python3 .github/workflows/changelog.py)
|
||||||
CHANGELOG="${CHANGELOG//'%'/'%25'}"
|
CHANGELOG="${CHANGELOG//'%'/'%25'}"
|
||||||
|
2
.github/workflows/create_stable_release.yml
vendored
2
.github/workflows/create_stable_release.yml
vendored
@ -47,6 +47,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-h1_h2-mayhem.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && zip -r sdcard.zip sdcard
|
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-h1_h2-mayhem.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && zip -r sdcard.zip sdcard
|
||||||
- name: Create changelog
|
- name: Create changelog
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
CHANGELOG=$(python3 .github/workflows/stable_changelog.py ${{ steps.past_version.outputs.past_version }})
|
CHANGELOG=$(python3 .github/workflows/stable_changelog.py ${{ steps.past_version.outputs.past_version }})
|
||||||
CHANGELOG="${CHANGELOG//'%'/'%25'}"
|
CHANGELOG="${CHANGELOG//'%'/'%25'}"
|
||||||
|
70
.github/workflows/stable_changelog.py
vendored
70
.github/workflows/stable_changelog.py
vendored
@ -1,21 +1,52 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
past_version = sys.argv[1]
|
past_version = sys.argv[1]
|
||||||
|
|
||||||
raw_git = os.popen('git log ' + past_version + '..next --pretty=format:"- %h - {USERNAME}*+%al-%an*: %s"').read()
|
main_repo_url = "https://github.com/eried/portapack-mayhem.git"
|
||||||
|
main_repo_identifier = "eried/portapack-mayhem"
|
||||||
|
# ^^&^ change these if main repo changed
|
||||||
|
|
||||||
|
os.system('gh repo set-default ' + main_repo_url)
|
||||||
|
|
||||||
|
raw_git = os.popen('git log ' + past_version + '..next --pretty=format:"- ^%h^ - {USERNAME}*_%al_%an*: %s"').read()
|
||||||
|
|
||||||
|
|
||||||
|
# ^ as github's rule, a real username can contains "-" but not "_" and "*", so use these two to seperate things
|
||||||
|
|
||||||
|
# during test at 2023-07-10, %al could return 3 different types of values:
|
||||||
|
# 123+abc <<<< abc is real username
|
||||||
|
# def <<<< def is 3rd level domain of unhidden email, drop this, fetch info from github cli client
|
||||||
|
# note that github will probably change in the future
|
||||||
|
|
||||||
def compute_username(line):
|
def compute_username(line):
|
||||||
stripped = re.search(r'(?<=\*)(.*?)(?=\*)', line).group(0)
|
line_org = line
|
||||||
|
stripped = re.search(r'(?<=\*)(.*?)(?=\*)', line).group(0) # get the string between "*" and "*"
|
||||||
|
now_item_hash = re.search(r'(?<=\^)(.*?)(?=\^)', line).group(0) # get the string between "*" and "*"
|
||||||
|
stripped_org = stripped
|
||||||
|
stripped = re.search(r'(?<=\_)(.*?)(?=\_)', stripped).group(0) # get the string between "_" and "_"
|
||||||
|
stripped_fallback = stripped
|
||||||
|
# now it's like "123+abc" or "def"
|
||||||
|
|
||||||
|
if ("+" in stripped): # 123+abc
|
||||||
|
stripped = re.sub(r'^.*?\+', "", stripped)
|
||||||
|
elif not ("+" in stripped): # maybe not real username, dropped, fetch from github cli client
|
||||||
|
fetched_now_item_json = os.popen(
|
||||||
|
'gh search commits repo:' + main_repo_identifier + ' --json author --hash ' + now_item_hash).read()
|
||||||
|
stripped = extract_first_login(fetched_now_item_json)
|
||||||
|
if stripped is False: # 403
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
elif stripped == "app/":
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
else: # exception and edge cases
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
|
||||||
|
if stripped is None: # if commit hash can't find AKA commit is only in fork
|
||||||
|
return "@" + stripped_fallback
|
||||||
|
|
||||||
pattern = re.compile("[$@+&?].*[$@+&?]")
|
|
||||||
if pattern.match(stripped):
|
|
||||||
stripped = re.sub("[$@+&?].*[$@+&?]", "", stripped)
|
|
||||||
stripped = re.match(r'.+?(?=-)', stripped).group(0)
|
|
||||||
else:
|
|
||||||
stripped = re.sub(r'^.*?-', "", stripped)
|
|
||||||
return "@" + stripped
|
return "@" + stripped
|
||||||
|
|
||||||
|
|
||||||
@ -23,8 +54,31 @@ def compile_line(line):
|
|||||||
username = compute_username(line)
|
username = compute_username(line)
|
||||||
line = re.sub(r'[*].*[*]', "", line)
|
line = re.sub(r'[*].*[*]', "", line)
|
||||||
line = line.replace("{USERNAME}", username)
|
line = line.replace("{USERNAME}", username)
|
||||||
|
line = re.sub(r'\^', '', line, count=2)
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
def extract_first_login(json_data):
|
||||||
|
if not json_data: # if returned null
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(json_data)
|
||||||
|
|
||||||
|
if isinstance(data, list) and len(data) > 0:
|
||||||
|
first_object = data[0]
|
||||||
|
if 'author' in first_object and 'login' in first_object['author']:
|
||||||
|
return first_object['author']['login']
|
||||||
|
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.code == 403 and "API rate limit exceeded" in str(e):
|
||||||
|
return False
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
for row in raw_git.splitlines():
|
for row in raw_git.splitlines():
|
||||||
print(compile_line(row))
|
print(compile_line(row))
|
||||||
|
Loading…
Reference in New Issue
Block a user