Skip to content

Commit

Permalink
Enable GitAuto to draft a X post when a PR is merged
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshinishio committed Dec 15, 2024
1 parent 3a00ec4 commit d3dc9c0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/x-post-draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create X Post Draft

on:
pull_request:
types: [closed]
branches:
- main

jobs:
create-x-post-draft:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4

# https://github.com/actions/setup-node
- uses: actions/setup-node@v4
with:
node-version: '20' # Updated to latest LTS version

# https://github.com/plhery/node-twitter-api-v2
- name: Install dependencies
run: npm install twitter-api-v2

# https://github.com/actions/github-script
- name: Create X Post Draft
uses: actions/github-script@v7
with:
script: |
const { TwitterApi } = require('twitter-api-v2');
// Initialize with bearer token
const client = new TwitterApi(process.env.TWITTER_BEARER_TOKEN);
const tweet = `🚀 New merge: ${context.payload.pull_request.title}\n\n${context.payload.pull_request.html_url}`;
await client.v2.tweet(tweet, { draft_mode: true });
env:
TWITTER_BEARER_TOKEN: ${{ secrets.TWITTER_BEARER_TOKEN }}

0 comments on commit d3dc9c0

Please sign in to comment.