mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
CI: Add script to post mastodon toots for commits on master
This patch adds the toot-commits script (mirroring tweet-commits), posting new commits on the master branch to https://serenityos.social/@commits.
This commit is contained in:
parent
7955cb14fb
commit
143f28b735
Notes:
sideshowbarker
2024-07-17 03:45:48 +09:00
Author: https://github.com/networkException Commit: https://github.com/SerenityOS/serenity/commit/143f28b735 Pull-request: https://github.com/SerenityOS/serenity/pull/17409 Reviewed-by: https://github.com/krkk Reviewed-by: https://github.com/linusg
@ -1,4 +1,4 @@
|
||||
name: Twitter notifications
|
||||
name: Social media notifications
|
||||
|
||||
on: [ push ]
|
||||
|
||||
@ -22,3 +22,20 @@ jobs:
|
||||
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
|
||||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
|
||||
|
||||
notify_mastodon:
|
||||
runs-on: ubuntu-22.04
|
||||
if: always() && github.repository == 'SerenityOS/serenity' && github.ref == 'refs/heads/master'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '14'
|
||||
- run: npm i mastodon
|
||||
- run: |
|
||||
node ${{ github.workspace }}/Meta/toot-commits.js << 'EOF'
|
||||
${{ toJSON(github.event) }}
|
||||
EOF
|
||||
env:
|
||||
ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
|
34
Meta/toot-commits.js
Normal file
34
Meta/toot-commits.js
Normal file
@ -0,0 +1,34 @@
|
||||
const fs = require("fs");
|
||||
const Mastodon = require("mastodon");
|
||||
const { ACCESS_TOKEN } = process.env;
|
||||
const tootLength = 500;
|
||||
// Mastodon always considers links to be 23 chars, see https://docs.joinmastodon.org/user/posting/#links
|
||||
const mastodonLinkLength = 23;
|
||||
|
||||
const mastodon = new Mastodon({
|
||||
access_token: ACCESS_TOKEN,
|
||||
timeout_ms: 60 * 1000,
|
||||
api_url: "https://serenityos.social/api/v1/",
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const githubEvent = JSON.parse(fs.readFileSync(0).toString());
|
||||
const toots = [];
|
||||
for (const commit of githubEvent["commits"]) {
|
||||
const authorLine = `Author: ${commit["author"]["name"]}`;
|
||||
const maxMessageLength = tootLength - authorLine.length - mastodonLinkLength - 2; // -2 for newlines
|
||||
const commitMessage =
|
||||
commit["message"].length > maxMessageLength
|
||||
? commit["message"].substring(0, maxMessageLength - 2) + "…" // Ellipsis counts as 2 characters
|
||||
: commit["message"];
|
||||
|
||||
toots.push(`${commitMessage}\n${authorLine}\n${commit["url"]}`);
|
||||
}
|
||||
for (const toot of toots) {
|
||||
try {
|
||||
await mastodon.post("statuses", { status: toot, visibility: "unlisted" });
|
||||
} catch (e) {
|
||||
console.error("Failed to post a toot!", e.message);
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue
Block a user