mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Meta: Ensure long messages fit in commit tweet
Abbreviating the commit message to 240 characters was not always enough. As a bonus, we now add an ellipsis to abbreviated messages.
This commit is contained in:
parent
22b0cbe1fe
commit
0e680cb17a
Notes:
sideshowbarker
2024-07-18 12:05:48 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/0e680cb17a0 Pull-request: https://github.com/SerenityOS/serenity/pull/8130 Reviewed-by: https://github.com/IdanHo ✅ Reviewed-by: https://github.com/linusg
@ -1,6 +1,9 @@
|
||||
const fs = require("fs");
|
||||
const Twit = require("twit");
|
||||
const { CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET } = process.env;
|
||||
const tweetLength = 280;
|
||||
// Twitter always considers t.co links to be 23 chars, see https://help.twitter.com/en/using-twitter/how-to-tweet-a-link
|
||||
const twitterLinkLength = 23;
|
||||
|
||||
const T = new Twit({
|
||||
consumer_key: CONSUMER_KEY,
|
||||
@ -13,11 +16,14 @@ const T = new Twit({
|
||||
const githubEvent = JSON.parse(fs.readFileSync(0).toString());
|
||||
const tweets = [];
|
||||
for (const commit of githubEvent["commits"]) {
|
||||
tweets.push(
|
||||
`${commit["message"].substring(0, 240)}\nAuthor: ${commit["author"]["name"]}\n${
|
||||
commit["url"]
|
||||
}`
|
||||
);
|
||||
const authorLine = `Author: ${commit["author"]["name"]}`;
|
||||
const maxMessageLength = tweetLength - authorLine.length - twitterLinkLength - 2; // -2 for newlines
|
||||
const commitMessage =
|
||||
commit["message"].length > maxMessageLength
|
||||
? commit["message"].substring(0, maxMessageLength - 2) + "…" // Ellipsis counts as 2 characters
|
||||
: commit["message"];
|
||||
|
||||
tweets.push(`${commitMessage}\n${authorLine}\n${commit["url"]}`);
|
||||
}
|
||||
for (const tweet of tweets) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user