Skip to content

Repo Management

Repo Management #630

Workflow file for this run

name: Repo Management
on:
pull_request_target:
types: [closed]
schedule:
- cron: "0 0 * * *" # 每天午夜运行
push:
branches: [main] # 每次推送到main分支时也运行
permissions:
contents: write
pull-requests: write
jobs:
update-readme:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub pytz
- name: Update README
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
START_DATE: ${{ vars.START_DATE }}
END_DATE: ${{vars.END_DATE }}
FILE_SUFFIX: ${{vars.FILE_SUFFIX}}
FIELD_NAME: ${{vars.FIELD_NAME}}
run: python sync_status_readme.py
- name: Check for changes
id: git-check
run: |
git diff --exit-code README.md || echo "modified=true" >> $GITHUB_OUTPUT
- name: Commit changes
if: steps.git-check.outputs.modified == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update commit status table"
git push
notify-api:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true || github.event_name == 'push'
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Install axios
run: npm install axios
- name: Call API
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const axios = require('axios');
const commit_sha = context.sha;
const { owner, repo } = context.repo;
try {
const { data: commit } = await github.rest.repos.getCommit({
owner,
repo,
ref: commit_sha
});
// Get user details
const { data: user } = await github.rest.users.getByUsername({
username: commit.author.login
});
// Output information
console.log('Commit Author Information:');
console.log('------------------------');
console.log(`Name: ${commit.commit.author.name}`);
console.log(`Email: ${commit.commit.author.email}`);
console.log(`GitHub Username: ${commit.author.login}`);
console.log(`User ID: ${user.id}`);
console.log(`Account Type: ${user.type}`);
console.log(`Created At: ${user.created_at}`);
const response = await axios.get(`https://api.intensivecolearn.ing/api/programs/createByRepo/${owner}/${repo}`);
console.log('API response:', response.data);
const updateUserNotesResp = await axios.get(`https://api.intensivecolearn.ing/api/programs/updateStudynotes?owner=${owner}&repo=${repo}&userGitId=${user.id}`);
console.log('updateUserNotesRespAPI response:', updateUserNotesResp.data);
} catch (error) {
console.error('Error calling API:', error.message);
core.setFailed(`Error calling API: ${error.message}`);
}