Skip to content

Commit 0b2404a

Browse files
committed
Rename X auth env vars for release announcements
1 parent 122cb9a commit 0b2404a

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ jobs:
248248
DISCORD_RELEASE_WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
249249
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
250250
REPOSITORY: ${{ github.repository }}
251+
X_CONSUMER_KEY: ${{ secrets.X_CONSUMER_KEY }}
252+
X_CONSUMER_KEY_SECRET: ${{ secrets.X_CONSUMER_KEY_SECRET }}
251253
X_ACCESS_TOKEN: ${{ secrets.X_ACCESS_TOKEN }}
252254
X_ACCESS_TOKEN_SECRET: ${{ secrets.X_ACCESS_TOKEN_SECRET }}
253-
X_API_KEY: ${{ secrets.X_API_KEY }}
254-
X_API_SECRET: ${{ secrets.X_API_SECRET }}
255255
shell: bash
256256
run: |
257257
args=(

packages/release/src/announcement.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import fs from "fs-extra";
55
import {
66
type AnnouncementContext,
77
appendAnnouncementMarker,
8+
buildXOAuth1,
89
loadChangelogRelease,
910
prepareStoredDiscordAnnouncement,
1011
prepareStoredXAnnouncement,
@@ -401,4 +402,38 @@ Release summary.
401402
"Skipped because the changelog frontmatter is empty"
402403
);
403404
});
405+
406+
it("builds OAuth1 auth with the X dashboard consumer env vars", () => {
407+
const oauth1 = buildXOAuth1({
408+
X_CONSUMER_KEY: "consumer-key",
409+
X_CONSUMER_KEY_SECRET: "consumer-secret",
410+
X_ACCESS_TOKEN: "access-token",
411+
X_ACCESS_TOKEN_SECRET: "access-token-secret",
412+
});
413+
const config = (oauth1 as any).config as {
414+
apiKey: string;
415+
apiSecret: string;
416+
callback: string;
417+
accessToken: string;
418+
accessTokenSecret: string;
419+
};
420+
421+
expect(config).toEqual({
422+
apiKey: "consumer-key",
423+
apiSecret: "consumer-secret",
424+
callback: "oob",
425+
accessToken: "access-token",
426+
accessTokenSecret: "access-token-secret",
427+
});
428+
});
429+
430+
it("reports missing X consumer env vars with the renamed keys", () => {
431+
expect(() =>
432+
buildXOAuth1({
433+
X_CONSUMER_KEY: "consumer-key",
434+
X_ACCESS_TOKEN: "access-token",
435+
X_ACCESS_TOKEN_SECRET: "access-token-secret",
436+
})
437+
).toThrow("X_CONSUMER_KEY_SECRET environment variable is required.");
438+
});
404439
});

packages/release/src/announcement.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,26 @@ export async function publishXAnnouncement(
578578
announcement: string,
579579
environment: Record<string, string | undefined>
580580
): Promise<void> {
581-
const oauth1 = new OAuth1({
582-
apiKey: getRequiredEnv(environment, "X_API_KEY"),
583-
apiSecret: getRequiredEnv(environment, "X_API_SECRET"),
584-
callback: "oob",
585-
accessToken: getRequiredEnv(environment, "X_ACCESS_TOKEN"),
586-
accessTokenSecret: getRequiredEnv(environment, "X_ACCESS_TOKEN_SECRET"),
581+
const client = new Client({
582+
oauth1: buildXOAuth1(environment),
587583
});
588-
589-
const client = new Client({ oauth1 });
590584
await client.posts.create({
591585
text: announcement,
592586
});
593587
}
594588

589+
export function buildXOAuth1(
590+
environment: Record<string, string | undefined>
591+
): OAuth1 {
592+
return new OAuth1({
593+
apiKey: getRequiredEnv(environment, "X_CONSUMER_KEY"),
594+
apiSecret: getRequiredEnv(environment, "X_CONSUMER_KEY_SECRET"),
595+
callback: "oob",
596+
accessToken: getRequiredEnv(environment, "X_ACCESS_TOKEN"),
597+
accessTokenSecret: getRequiredEnv(environment, "X_ACCESS_TOKEN_SECRET"),
598+
});
599+
}
600+
595601
function renderSummary(result: RunWidgetReleaseAnnouncementResult): string {
596602
const lines = [
597603
"## Widget Release Announcements",

0 commit comments

Comments
 (0)