Add new line to test53354 #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sticky Discord Notification | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| paths: | |
| - "sticky/**" | |
| jobs: | |
| discord: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Send latest Sticky commit to Discord | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_STICKY }} | |
| COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | |
| COMMIT_URL: ${{ github.event.head_commit.html_url }} | |
| COMMIT_SHA: ${{ github.event.head_commit.id }} | |
| AUTHOR: ${{ github.event.head_commit.author.name }} | |
| AUTHOR_USERNAME: ${{ github.event.head_commit.author.username }} | |
| BRANCH: ${{ github.ref_name }} | |
| REPO: ${{ github.repository }} | |
| BEFORE: ${{ github.event.before }} | |
| run: | | |
| python3 - <<'PY' | |
| import json | |
| import os | |
| import urllib.request | |
| import urllib.error | |
| import datetime | |
| sha = os.environ["COMMIT_SHA"] | |
| short_sha = sha[:7] | |
| repo = os.environ["REPO"] | |
| commit_url = os.environ["COMMIT_URL"] | |
| branch = os.environ["BRANCH"] | |
| author = os.environ["AUTHOR"] or "Unknown" | |
| author_username = os.environ.get("AUTHOR_USERNAME", "").strip() | |
| before = os.environ.get("BEFORE", "").strip() | |
| repo_url = f"https://github.com/{repo}" | |
| files_url = f"{commit_url}/files" | |
| branch_url = f"{repo_url}/tree/{branch}" | |
| author_url = f"https://github.com/{author_username}" if author_username else repo_url | |
| links = [ | |
| f"[`{short_sha}`]({commit_url})", | |
| f"[View changes]({files_url})", | |
| ] | |
| if before and set(before) != {"0"}: | |
| links.append(f"[Full diff]({repo_url}/compare/{before}...{sha})") | |
| embed = { | |
| "title": "New Sticky Update", | |
| "url": commit_url, | |
| "description": os.environ["COMMIT_MESSAGE"][:4000], | |
| "color": 0x5865F2, | |
| "author": {"name": author, "url": author_url}, | |
| "fields": [ | |
| {"name": "Branch", "value": f"[`{branch}`]({branch_url})", "inline": True}, | |
| {"name": "Commit", "value": f"[`{short_sha}`]({commit_url})", "inline": True}, | |
| {"name": "Links", "value": " · ".join(links), "inline": False}, | |
| ], | |
| "footer": {"text": repo}, | |
| "timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(), | |
| } | |
| if author_username: | |
| embed["author"]["icon_url"] = f"https://github.com/{author_username}.png" | |
| payload = { | |
| "username": "GitHub Sticky", | |
| "embeds": [embed], | |
| } | |
| request = urllib.request.Request( | |
| os.environ["DISCORD_WEBHOOK"], | |
| data=json.dumps(payload).encode("utf-8"), | |
| headers={ | |
| "Content-Type": "application/json", | |
| "User-Agent": "ToHubLab-Cogs/1.0 (+https://github.com/ToHubLab/ToHubLab-Cogs)", | |
| }, | |
| method="POST", | |
| ) | |
| try: | |
| with urllib.request.urlopen(request) as response: | |
| print("Discord HTTP", response.status) | |
| except urllib.error.HTTPError as e: | |
| print("Discord error:", e.code, e.reason) | |
| print(e.read().decode("utf-8", errors="replace")) | |
| raise | |
| PY |