Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
luffythink committed Sep 28, 2024
2 parents 4d68aa1 + ff8ec29 commit e6be7e1
Show file tree
Hide file tree
Showing 5 changed files with 594 additions and 63 deletions.
147 changes: 121 additions & 26 deletions .github/workflows/sync_status.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,127 @@
name: Sync Study Status
name: Repo Management

on: {}
#schedule:
# - cron: '0 0 * * *' # 每天午夜运行
#push:
# branches: [ main ] # 每次推送到main分支时也运行
on:
pull_request_target:
types: [closed]
schedule:
- cron: "0 0 * * *" # 每天午夜运行
push:
branches: [main] # 每次推送到main分支时也运行

permissions:
contents: write
pull-requests: write

jobs:
invite-contributor:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true
steps:
- name: Invite contributor
id: invite-contributor
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_WITH_INVITE_PERMISSIONS }}
script: |
const { owner, repo } = context.repo;
const username = context.payload.pull_request.user.login;
console.log(`Checking if ${username} is already a collaborator...`);
try {
const { data: permissionLevel } = await github.rest.repos.getCollaboratorPermissionLevel({
owner,
repo,
username,
});
if (permissionLevel.permission === 'admin' || permissionLevel.permission === 'write') {
console.log(`${username} is already a collaborator with sufficient permissions.`);
return;
}
console.log(`${username} is a collaborator but needs permission update.`);
} catch (error) {
if (error.status !== 404) {
console.error(`Error checking collaborator status: ${error.message}`);
throw error;
}
console.log(`${username} is not a collaborator.`);
}
try {
console.log(`Inviting ${username} as a collaborator...`);
const response = await github.rest.repos.addCollaborator({
owner,
repo,
username,
permission: 'push'
});
if (response.status === 201) {
console.log(`Invitation sent to ${username} as a collaborator with push permission.`);
core.setOutput('invitation_sent', 'true');
} else if (response.status === 204) {
console.log(`${username}'s permissions updated to push.`);
core.setOutput('invitation_sent', 'false');
}
} catch (error) {
console.error(`Error inviting/updating collaborator: ${error.message}`);
core.setFailed(`Error inviting/updating collaborator: ${error.message}`);
}
- name: Comment on PR
if: steps.invite-contributor.outputs.invitation_sent == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const username = context.payload.pull_request.user.login;
try {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `Thanks for your contribution, @${username}! You've been invited as a collaborator with push permissions. Please check your email for the invitation.`
});
console.log(`Comment posted on PR #${issue_number}`);
} catch (error) {
console.error(`Error posting comment: ${error.message}`);
core.setFailed(`Error posting comment: ${error.message}`);
}
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 }}
run: python sync_status_readme.py
- name: Commit changes
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" || exit 0
git push
- 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
17 changes: 17 additions & 0 deletions Derick_EICL2nd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# {Derick}

1. 自我介绍
2. 你认为你会完成本次残酷学习吗?

## Notes

<!-- Content_START -->

### 2024.09.30

笔记内容

### 2024.07.12

<!-- Content_END -->
41 changes: 5 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,13 @@ LXDAO Host 的英语残酷共学第 2 期将继续加强**听和说**的训练
✅ = Done ⭕️ = Missed ❌ = Failed

<!-- START_COMMIT_TABLE -->
| EICL2nd·Name | 9.30 | 10.01 | 10.02 | 10.03 | 10.04 | 10.05 | 10.06 | 10.07 | 10.08 | 10.09 | 10.10 | 10.11 | 10.12 | 10.13 | 10.14 | 10.15 | 10.16 | 10.17 | 10.18 | 10.19 | 10.20 | 10.21 | 10.22 | 10.23 | 10.24 | 10.25 | 10.26 | 10.27 | 10.28 |
| ------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| Derick | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<!-- END_COMMIT_TABLE -->


| EICL2st· Name | 10.08 | 10.09 | 10.10 | 10.11 | 10.12 | 10.13 | 10.14 | 10.15 | 10.16 | 10.17 | 10.18 | 10.19 | 10.20 | 10.21 | 10.22 | 10.23 | 10.24 | 10.25 | 10.26 | 10.27 | 10.28 |
| ------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |

<!-- END_COMMIT_TABLE -->



Expand Down
2 changes: 1 addition & 1 deletion Template_EICL2nd.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ timezone: Asia/Shanghai
### 2024.10.10



<!-- Content_END -->



Expand Down
Loading

0 comments on commit e6be7e1

Please sign in to comment.