Skip to content

Commit 17ca416

Browse files
authored
Merge pull request #219 from satisfactorymodding/githook-embed-update
Update githook embeds to credit commit author, not commit committer
2 parents 3d4b3ab + 16ba4ba commit 17ca416

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

fred/libraries/createembed.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,22 @@ def DM(text: str) -> nextcord.Embed:
7979
return embed
8080

8181

82+
# data format: expand `commits` properties on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
8283
def format_commit(commit: dict) -> tuple[str, str]:
8384
hash_id = f'`{commit["id"][:8]}`'
8485
commit_message = commit["message"].split("\n")[0].replace("*", r"\*")
85-
author = commit["committer"]
86+
author = commit["author"]
8687
attribution = f'[{author["name"]}](https://github.com/{author["username"]})'
8788
ts = timestamp(commit["timestamp"])
8889
change_summary_icons = " ".join(
8990
[f"{em} {len(commit[k])}" for em, k in zip("✅❌📝", ["added", "removed", "modified"])]
9091
)
9192
return f"{commit_message}\n", f'{change_summary_icons} - by {attribution} {ts} [{hash_id}]({commit["url"]})\n'
9293

94+
def _append_legend_footer(embed: nextcord.Embed) -> None:
95+
embed.set_footer(text="Use the `" + config.Misc.fetch("prefix") + "legend` to learn what the icons mean!")
9396

97+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
9498
def push(data: dict) -> nextcord.Embed:
9599
if data["forced"]:
96100
colour = config.ActionColours.fetch("Red")
@@ -100,10 +104,10 @@ def push(data: dict) -> nextcord.Embed:
100104
forced = ""
101105

102106
if data["created"]:
103-
embed = create(data)
107+
embed = push_ref_create(data)
104108
return embed
105109
elif data["deleted"]:
106-
embed = delete(data)
110+
embed = push_ref_delete(data)
107111
return embed
108112

109113
commits = data["commits"]
@@ -122,11 +126,14 @@ def push(data: dict) -> nextcord.Embed:
122126
if not_shown := len(commits[24:]):
123127
embed.add_field(name=f"{not_shown} commits not shown", value="See GitHub for more details!", inline=False)
124128

129+
# Note: if we wanted to get user display name instead of username,
130+
# looks like we'd have to web request the `url` field then use the `name` field from the response
125131
embed.set_author(name=data["sender"]["login"], icon_url=data["sender"]["avatar_url"])
126-
embed.set_footer(text="Use the `" + config.Misc.fetch("prefix") + "legend` to learn what the icons mean!")
132+
_append_legend_footer(embed)
127133
return embed
128134

129135

136+
# data format: (note: docs on 'added' has empty data for `member` but it probably shares it with 'removed'?) https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=removed#member
130137
def contributor_added(data: dict) -> nextcord.Embed:
131138
embed = nextcord.Embed(
132139
title=f'__**{data["member"]["login"]}**__ has been added to the Repository!',
@@ -139,6 +146,7 @@ def contributor_added(data: dict) -> nextcord.Embed:
139146
return embed
140147

141148

149+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request
142150
def pull_request(data: dict) -> nextcord.Embed:
143151
action = data["action"]
144152
colour = config.ActionColours.fetch("Orange")
@@ -183,13 +191,12 @@ def pull_request(data: dict) -> nextcord.Embed:
183191

184192
direction = f'{data["pull_request"]["head"]["ref"]} -> {data["pull_request"]["base"]["ref"]}'
185193
embed.add_field(name=direction, value=stats)
186-
187-
embed.set_footer(text="Use the `" + config.Misc.fetch("prefix") + "legend` to learn what the icons mean!")
188-
194+
_append_legend_footer(embed)
189195
return embed
190196

191197

192-
def create(data: dict) -> nextcord.Embed:
198+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
199+
def push_ref_create(data: dict) -> nextcord.Embed:
193200
_, ref_type, ref_name = data["ref"].split("/")
194201
match ref_type:
195202
case "tags":
@@ -210,7 +217,8 @@ def create(data: dict) -> nextcord.Embed:
210217
return embed
211218

212219

213-
def delete(data: dict) -> nextcord.Embed:
220+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
221+
def push_ref_delete(data: dict) -> nextcord.Embed:
214222
_, ref_type, ref_name = data["ref"].split("/")
215223
embed = nextcord.Embed(
216224
title=f'{ref_type} "{ref_name}" deleted in {repo_name}',
@@ -223,6 +231,7 @@ def delete(data: dict) -> nextcord.Embed:
223231
return embed
224232

225233

234+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#release
226235
def release(data: dict) -> nextcord.Embed:
227236
state = "pre-release" if data["release"]["prerelease"] else "release"
228237
embed = nextcord.Embed(
@@ -236,6 +245,7 @@ def release(data: dict) -> nextcord.Embed:
236245
return embed
237246

238247

248+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#issues
239249
def issue(data: dict) -> nextcord.Embed:
240250
match action := data["action"]:
241251
case "opened":
@@ -257,6 +267,7 @@ def issue(data: dict) -> nextcord.Embed:
257267
return embed
258268

259269

270+
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment
260271
def issue_comment(data: dict) -> nextcord.Embed:
261272
author = data["comment"]["user"]
262273
embed = nextcord.Embed(

0 commit comments

Comments
 (0)