Skip to content

Commit

Permalink
Fix For Discord Changelog (DeltaV-Station#869)
Browse files Browse the repository at this point in the history
Signed-off-by: Evgencheg <[email protected]>
Co-authored-by: DEATHB4DEFEAT <[email protected]>
  • Loading branch information
Evgencheg and DEATHB4DEFEAT authored Sep 7, 2024
1 parent 93fe77e commit 73764c2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 68 deletions.
80 changes: 37 additions & 43 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }}
PR_NUMBER: ${{ github.event.number }}
CHANGELOG_WEBHOOK: ${{ secrets.CHANGELOG_WEBHOOK }}

jobs:
changelog:
Expand All @@ -17,45 +16,40 @@ jobs:
permissions:
contents: write
steps:
- name: Checkout Master
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_TOKEN }}
ref: "${{ vars.CHANGELOG_BRANCH }}"

- name: Setup Git
run: |
git config --global user.name "${{ vars.CHANGELOG_USER }}"
git config --global user.email "${{ vars.CHANGELOG_EMAIL }}"
shell: bash

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: |
cd "Tools/changelogs"
npm install
shell: bash
continue-on-error: true

- name: Generate Changelog
run: |
cd "Tools/changelogs"
node changelog.js
shell: bash
continue-on-error: true

- name: Commit Changelog
run: |
git add *.yml
git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})"
git push
shell: bash
continue-on-error: true

- name: Publish changelog
run: Tools/actions_changelogs_since_last_run.py
continue-on-error: true
- name: Checkout Master
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_TOKEN }}
ref: ${{ vars.CHANGELOG_BRANCH }}

- name: Setup Git
run: |
git config --global user.name "${{ vars.CHANGELOG_USER }}"
git config --global user.email "${{ vars.CHANGELOG_EMAIL }}"
shell: bash

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: |
cd "Tools/changelogs"
npm install
shell: bash

- name: Generate Changelog
run: |
cd "Tools/changelogs"
node changelog.js
shell: bash

- name: Commit Changelog
run: |
git pull origin master
git add *.yml
git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})"
git push
shell: bash
continue-on-error: true
23 changes: 23 additions & 0 deletions .github/workflows/discord-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Discord Changelog

on:
workflow_dispatch:
schedule:
- cron: '0 6 * * *'

jobs:
publish_changelog:
runs-on: ubuntu-latest
steps:

- name: checkout
uses: actions/checkout@v3
with:
ref: master

- name: Publish changelog
run: Tools/actions_changelogs_since_last_run.py
env:
CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }}
CHANGELOG_WEBHOOK: ${{ secrets.CHANGELOG_WEBHOOK }}
continue-on-error: true
36 changes: 11 additions & 25 deletions Tools/actions_changelogs_since_last_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
CHANGELOG_DIR = os.environ["CHANGELOG_DIR"]
CHANGELOG_WEBHOOK = os.environ["CHANGELOG_WEBHOOK"]
PR_NUMBER = os.environ["PR_NUMBER"]

# https://discord.com/developers/docs/resources/webhook
DISCORD_SPLIT_LIMIT = 2000

TYPES_TO_EMOJI = {
"Fix": "🐛",
"Add": "🆕",
"Add": "",
"Remove": "❌",
"Tweak": "⚒️"
}
Expand All @@ -41,21 +40,8 @@ def main():
session.headers["Accept"] = "Accept: application/vnd.github+json"
session.headers["X-GitHub-Api-Version"] = "2022-11-28"

resp = session.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/pulls/{PR_NUMBER}")
resp.raise_for_status()
last_sha = resp.json()["merge_commit_sha"]

index = int(PR_NUMBER)
while True:
index -= 1
resp = session.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/pulls/{index}")
resp.raise_for_status()
merge_info = resp.json()
if merge_info["merged_at"]:
last_sha = merge_info["merge_commit_sha"]
break

most_recent = get_most_recent_workflow(session)
last_sha = most_recent['head_commit']['id']
print(f"Last successful publish job was {most_recent['id']}: {last_sha}")
last_changelog = yaml.safe_load(get_last_changelog(session, last_sha))
with open(CHANGELOG_DIR, "r") as f:
Expand Down Expand Up @@ -121,14 +107,14 @@ def diff_changelog(old: dict[str, Any], cur: dict[str, Any]) -> Iterable[Changel

def get_discord_body(content: str):
return {
"content": content,
# Do not allow any mentions.
"allowed_mentions": {
"parse": []
},
# SUPPRESS_EMBEDS
"flags": 1 << 2
}
"content": content,
# Do not allow any mentions.
"allowed_mentions": {
"parse": []
},
# SUPPRESS_EMBEDS
"flags": 1 << 2
}


def send_discord(content: str):
Expand Down Expand Up @@ -159,7 +145,7 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
message = change['message']
url = entry.get("url")
if url and url.strip():
group_content.write(f"{emoji} [-]({url}) {message}\n")
group_content.write(f"{emoji} - [{message}]({url})\n")
else:
group_content.write(f"{emoji} - {message}\n")

Expand Down

0 comments on commit 73764c2

Please sign in to comment.