Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: write
pull-requests: write

concurrency:
group: process-json-${{ github.ref }}
Expand Down Expand Up @@ -54,12 +55,34 @@ jobs:
env:
BLUESKY_IDENTIFIER_NODEJS_ORG: nodejs.org
BLUESKY_APP_PASSWORD_NODEJS_ORG: ${{ secrets.BLUESKY_APP_PASSWORD_NODEJS_ORG }}
POST_URLS_FILE: ${{ runner.temp }}/bluesky-post-urls.txt
run: |
: > "$POST_URLS_FILE"
for file in ${{ steps.find-json.outputs.NEW_JSON_FILES }}; do
echo "Processing $file..."
node actions/process.js "$file"
done

# Comment browsable bsky.app links on the merged PR (nodejs/bluesky#9).
- name: Comment post links on the PR
if: steps.find-json.outputs.NEW_JSON_FILES
env:
GH_TOKEN: ${{ github.token }}
POST_URLS_FILE: ${{ runner.temp }}/bluesky-post-urls.txt
run: |
if [ ! -s "$POST_URLS_FILE" ]; then
echo "No post URLs to comment"
exit 0
fi
{
echo "Posted to Bluesky:"
echo
while IFS= read -r url; do
[ -n "$url" ] && echo "- $url"
done < "$POST_URLS_FILE"
} > "${{ runner.temp }}/pr-comment.md"
gh pr comment "${{ github.event.pull_request.number }}" --body-file "${{ runner.temp }}/pr-comment.md"

- name: Commit and push changes
if: steps.find-json.outputs.NEW_JSON_FILES
run: |
Expand Down
34 changes: 33 additions & 1 deletion actions/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'node:fs';
import assert from 'node:assert';
import process from 'node:process';
import path from 'node:path';
import { post, maybeUpdateReplyInThread } from './lib/posts.js';
import { post, maybeUpdateReplyInThread, getPostURLFromURI } from './lib/posts.js';

// This script takes a path to a JSON with the pattern $base_path/new/$any_name.json,
// where $any_name can be anything, and then performs the action specified in it.
Expand All @@ -13,6 +13,34 @@ import { post, maybeUpdateReplyInThread } from './lib/posts.js';
// starting from 0 based on the number of existing JSONs processed on the same date
// and already in the processed directory.

/**
* Resolve a browsable bsky.app URL for the performed action.
* Reposts create `app.bsky.feed.repost` records (not /post/ URLs), so link the
* original post instead.
* @param {import('@atproto/api').AtpAgent} agent
* @param {{ action: string, repostURL?: string }} request
* @param {{ uri: string }} result
*/
async function getPublicPostURL(agent, request, result) {
if (request.action === 'repost') {
return request.repostURL;
}
return getPostURLFromURI(agent, result.uri);
}

/**
* When POST_URLS_FILE is set (GitHub Actions), append URLs so the workflow can
* comment them on the merged PR.
* @param {string} postURL
*/
function appendPostURLForPRComment(postURL) {
const urlsFile = process.env.POST_URLS_FILE;
if (!urlsFile) {
return;
}
fs.appendFileSync(urlsFile, `${postURL}\n`);
}

assert(process.argv[2], `Usage: node process.js $base_path/new/$any_name.json`);
const { agent, requests, requestFilePath, richTextFile } = await import('./login-and-validate.js');

Expand Down Expand Up @@ -47,6 +75,10 @@ for (const request of requests) {
assert.fail('Unknown action ' + request.action);
}
console.log('Result', result);
const postURL = await getPublicPostURL(agent, request, result);
console.log('Post URL', postURL);
result.postURL = postURL;
appendPostURLForPRComment(postURL);
// Extend the result to be written to the processed JSON file.
request.result = result;
previousPostInfo = {
Expand Down