Skip to content

prompt toolkit for autofill #27

prompt toolkit for autofill

prompt toolkit for autofill #27

Workflow file for this run

name: Post to X on Announce
on:
push:
branches:
- master
jobs:
post-to-x:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if commit contains [announce]
id: check_announce
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" == *"[announce]"* ]]; then
echo "should_post=true" >> $GITHUB_OUTPUT
else
echo "should_post=false" >> $GITHUB_OUTPUT
fi
- name: Extract commit info
if: steps.check_announce.outputs.should_post == 'true'
id: commit_info
run: |
COMMIT_HASH=$(git log -1 --pretty=%h)
COMMIT_MSG=$(git log -1 --pretty=%B)
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
COMMIT_URL="https://github.com/YSMsimon/this-is-my-agent/commit/$COMMIT_HASH"
# Remove [announce] tag from message for cleaner output
CLEAN_MSG="${COMMIT_MSG//\[announce\]/}"
CLEAN_MSG=$(echo "$CLEAN_MSG" | xargs)
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
echo "commit_msg=$CLEAN_MSG" >> $GITHUB_OUTPUT
echo "commit_author=$COMMIT_AUTHOR" >> $GITHUB_OUTPUT
echo "commit_url=$COMMIT_URL" >> $GITHUB_OUTPUT
- name: Setup Node.js
if: steps.check_announce.outputs.should_post == 'true'
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
if: steps.check_announce.outputs.should_post == 'true'
run: npm install twitter-api-v2
- name: Post to X (English and Chinese)
if: steps.check_announce.outputs.should_post == 'true'
env:
X_API_KEY: ${{ secrets.X_API_KEY }}
X_API_SECRET: ${{ secrets.X_API_SECRET }}
X_ACCESS_TOKEN: ${{ secrets.X_ACCESS_TOKEN }}
X_ACCESS_TOKEN_SECRET: ${{ secrets.X_ACCESS_TOKEN_SECRET }}
COMMIT_MSG: ${{ steps.commit_info.outputs.commit_msg }}
COMMIT_AUTHOR: ${{ steps.commit_info.outputs.commit_author }}
COMMIT_URL: ${{ steps.commit_info.outputs.commit_url }}
run: |
# Create Node.js script to post tweets in both languages
cat > post_tweets.js << 'EOF'
const { TwitterApi } = require('twitter-api-v2');
const client = new TwitterApi({
appKey: process.env.X_API_KEY,
appSecret: process.env.X_API_SECRET,
accessToken: process.env.X_ACCESS_TOKEN,
accessSecret: process.env.X_ACCESS_TOKEN_SECRET,
});
// English version
const englishTweet = `🚀 Update: ${process.env.COMMIT_MSG}
By: ${process.env.COMMIT_AUTHOR}
${process.env.COMMIT_URL}
#AIAgent #LocalLLM #Python`;
// Chinese version
const chineseTweet = `🚀 更新: ${process.env.COMMIT_MSG}
作者: ${process.env.COMMIT_AUTHOR}
${process.env.COMMIT_URL}
#AI代理 #本地LLM #Python`;
(async () => {
try {
// Post English tweet
console.log('\n📝 Posting English version...');
const englishPost = await client.v2.tweet(englishTweet);
console.log('✅ English tweet posted successfully!');
console.log('Tweet ID:', englishPost.data.id);
console.log('Tweet text:', englishTweet);
// Wait 2 seconds between posts
await new Promise(resolve => setTimeout(resolve, 2000));
// Post Chinese tweet
console.log('\n📝 Posting Chinese version...');
const chinesePost = await client.v2.tweet(chineseTweet);
console.log('✅ Chinese tweet posted successfully!');
console.log('Tweet ID:', chinesePost.data.id);
console.log('Tweet text:', chineseTweet);
console.log('\n✨ Both tweets posted successfully!');
} catch (error) {
console.error('❌ Failed to post tweet:', error.message);
process.exit(1);
}
})();
EOF
# Run the script
node post_tweets.js