Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sync_status_readme.py #61

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/ReopBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,60 @@ jobs:
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}`);
}
11 changes: 8 additions & 3 deletions sync_status_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
END_DATE = datetime.fromisoformat(os.environ.get(
'END_DATE', '2024-07-14T23:59:59+00:00')).replace(tzinfo=pytz.UTC)
DEFAULT_TIMEZONE = 'Asia/Shanghai'
FILE_SUFFIX = os.environ.get('FILE_SUFFIX', '_EICL1st.md')
FILE_SUFFIX = os.environ.get('FILE_SUFFIX', '.md')
README_FILE = 'README.md'
FIELD_NAME = os.environ.get('FIELD_NAME', 'EICL1st· Name')
FIELD_NAME = os.environ.get('FIELD_NAME', 'Name')
Content_START_MARKER = "<!-- Content_START -->"
Content_END_MARKER = "<!-- Content_END -->"
TABLE_START_MARKER = "<!-- START_COMMIT_TABLE -->"
Expand Down Expand Up @@ -351,6 +351,7 @@ def calculate_statistics(content):
eliminated_participants = 0
completed_participants = 0
perfect_attendance_users = []
completed_users = []

for row in rows:
user_name = row.split('|')[1].strip()
Expand All @@ -361,9 +362,11 @@ def calculate_statistics(content):
eliminated_participants += 1
elif all(status == '✅' for status in statuses):
completed_participants += 1
completed_users.append(user_name)
perfect_attendance_users.append(user_name)
elif all(status in ['✅', '⭕️', ' '] for status in statuses):
completed_participants += 1
completed_users.append(user_name)

elimination_rate = (eliminated_participants /
total_participants) * 100 if total_participants > 0 else 0
Expand All @@ -375,7 +378,8 @@ def calculate_statistics(content):
'eliminated_participants': eliminated_participants,
'elimination_rate': elimination_rate,
'fork_count': fork_count,
'perfect_attendance_users': perfect_attendance_users
'perfect_attendance_users': perfect_attendance_users,
'completed_users': completed_users
}


Expand Down Expand Up @@ -403,6 +407,7 @@ def main():
stats_content = f"\n\n## 统计数据\n\n"
stats_content += f"- 总参与人数: {stats['total_participants']}\n"
stats_content += f"- 完成人数: {stats['completed_participants']}\n"
stats_content += f"- 完成用户: {', '.join(stats['completed_users'])}\n"
stats_content += f"- 全勤用户: {', '.join(stats['perfect_attendance_users'])}\n"
stats_content += f"- 淘汰人数: {stats['eliminated_participants']}\n"
stats_content += f"- 淘汰率: {stats['elimination_rate']:.2f}%\n"
Expand Down
Loading