Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajouter une option pour générer la pull request avec mkchangelog #3973

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/mkchangelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
with:
python-version: "3.11"
- name: 📥 Generate changelog
run: scripts/mkchangelog
run: scripts/mkchangelog --publish
env:
GH_TOKEN: ${{ secrets.ITOU_TECH_GH_TOKEN }}
50 changes: 41 additions & 9 deletions scripts/mkchangelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3


import argparse
import datetime
import json
import logging
Expand All @@ -14,6 +15,12 @@ import tempfile

logger = logging.getLogger(__name__)

ADDED = "ajouté"
CHANGED = "modifié"
REMOVED = "supprimé"
SKIP = "no-changelog"
DEPS = "dependencies"


def gh(*args, **kwargs):
env = (
Expand Down Expand Up @@ -51,18 +58,18 @@ def list_pull_requests(start, end, labels):


def list_missing_pull_requests(start, end):
return list_pull_requests(start, end, "-label:ajouté,modifié,supprimé,dependencies,no-changelog")
return list_pull_requests(start, end, f"-label:{ADDED},{CHANGED},{REMOVED},{DEPS},{SKIP}")


def list_merged_pull_requests(start, end):
return list_pull_requests(start, end, "label:ajouté,modifié,supprimé")
return list_pull_requests(start, end, f"label:{ADDED},{CHANGED},{REMOVED}")


def open_pull_request(branch, title):
gh("pr", "create", "--label", "no-changelog", "--title", title, "--body", "")
gh("pr", "create", "--label", SKIP, "--title", title, "--body", "")


def main():
def main(publish):
changelog_path = pathlib.Path("CHANGELOG.md")
with (
open(changelog_path, "r+") as changelog,
Expand Down Expand Up @@ -91,14 +98,14 @@ def main():
if re.search(r"\!\[[^]]+]", pull_request["body"]):
title += " 🖼"
labels = [label["name"] for label in pull_request["labels"]]
if len({"ajouté", "modifié", "supprimé"}.intersection(set(labels))) != 1:
if len({ADDED, CHANGED, REMOVED}.intersection(set(labels))) != 1:
label_names = " ".join(labels)
raise ValueError(
f"Expected only one of “ajouté”, “modifié” or “supprimé” in labels, got {label_names}."
f"Expected only one of “{ADDED}”, “{CHANGED}” or “{REMOVED}” in labels, got {label_names}."
)
if "ajouté" in labels:
if ADDED in labels:
added.append(title)
elif "modifié" in labels:
elif CHANGED in labels:
changed.append(title)
else:
removed.append(title)
Expand Down Expand Up @@ -131,6 +138,31 @@ def main():
finally:
pathlib.Path(new_changelog.name).unlink(missing_ok=True)

if publish:
branch = f"changelog/{sprint_end}"
sprint_end_inclusive = sprint_end - datetime.timedelta(days=1)
title = f"changelog: From {sprint_start} to {sprint_end_inclusive}"
subprocess.run(["git", "switch", "--create", branch], check=True)
subprocess.run(
[
"git",
"-c",
"user.name=Changelog Bot",
"-c",
"[email protected]",
"commit",
"--all",
"--message",
title,
],
check=True,
)
subprocess.run(["git", "push", "--set-upstream", "origin", branch], check=True)
open_pull_request(branch, title)


if __name__ == "__main__":
main()
parser = argparse.ArgumentParser()
parser.add_argument("--publish")
args = parser.parse_args()
main(args.publish)