pip install octokit
,等一会儿就能安装好。装完之后,得搞定认证问题,毕竟要访问 GitHub 的数据,没权限可不行。from octokit import Octokit
octokit = Octokit(auth="你的个人访问令牌")
octokit
对象去调用 GitHub 的 API 啦。name: Test Workflow
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: python -m pytest
.github/workflows/
目录下。代码大概是这样的:repo_owner = "你的用户名"
repo_name = "你的仓库名"
workflow_path = ".github/workflows/test_workflow.yml"
workflow_content = "刚才写的 YAML 内容"
octokit.rest.repos.create_or_update_file_contents(
owner=repo_owner,
repo=repo_name,
path=workflow_path,
message="Add test workflow",
content=workflow_content.encode("utf-8").hex(),
sha=get_existing_file_sha(octokit, repo_owner, repo_name, workflow_path) # 如果文件不存在,sha 可以设为 None
)
workflows = octokit.rest.actions.list_repo_workflows(
owner=repo_owner,
repo=repo_name
).data
for workflow in workflows:
print(f"工作流名称:{workflow['name']},ID:{workflow['id']}")
workflow_id = # 替换成实际的工作流 ID
runs = octokit.rest.actions.list_workflow_runs(
owner=repo_owner,
repo=repo_name,
workflow_id=workflow_id
).data
for run in runs:
print(f"运行 ID:{run['id']},状态:{run['status']},结论:{run['conclusion']}")
workflow_dispatch
事件。octokit.rest.actions.create_workflow_dispatch(
owner=repo_owner,
repo=repo_name,
workflow_id=workflow_id
)
commits = octokit.rest.repos.list_commits(
owner=repo_owner,
repo=repo_name,
sha="main"
).data
for commit in commits:
print(f"提交哈希:{commit['sha']},作者:{commit['commit']['author']['name']},提交时间:{commit['commit']['author']['date']}")
issues = octokit.rest.issues.list_repo_issues(
owner=repo_owner,
repo=repo_name,
state="open"
).data
from datetime import datetime
monthly_commits = {}
for commit in commits:
commit_date = datetime.strptime(commit['commit']['author']['date'], "%Y-%m-%dT%H:%M:%SZ")
month = commit_date.strftime("%Y-%m")
if month in monthly_commits:
monthly_commits[month] +=
else:
monthly_commits[month] =
print("每月提交次数:")
for month, count in monthly_commits.items():
print(f"{month}:{count} 次")
issue_status = {}
for issue in issues:
status = issue['state']
if status in issue_status:
issue_status[status] +=
else:
issue_status[status] =
print("Issues 状态分布:")
for status, count in issue_status.items():
print(f"{status}:{count} 个")
import matplotlib.pyplot as plt
months = list(monthly_commits.keys())
counts = list(monthly_commits.values())
plt.figure(figsize=(, ))
plt.plot(months, counts, marker='o')
plt.title("每月提交次数趋势")
plt.xlabel("月份")
plt.ylabel("提交次数")
plt.xticks(rotation=)
plt.grid(True)
plt.show()
plt.figure(figsize=(, ))
plt.pie(counts, labels=statuses, autopct='%1.1f%%')
plt.title("Issues 状态分布")
plt.axis('equal')
plt.show()
pip install matplotlib
就能安装。page
和 per_page
参数获取更多数据:page =
per_page =
while True:
commits = octokit.rest.repos.list_commits(
owner=repo_owner,
repo=repo_name,
sha="main",
page=page,
per_page=per_page
).data
if not commits:
break
# 处理当前页的数据
page +=
workflow_dispatch
事件。aiohttp
库,安装之后,代码大概是这样的:import asyncio
from octokit import AsyncOctokit
async def main():
async with AsyncOctokit(auth="你的个人访问令牌") as octokit:
workflows = await octokit.rest.actions.list_repo_workflows(
owner=repo_owner,
repo=repo_name
)
print(workflows.data)
asyncio.run(main())
def count_monthly_commits(commits):
monthly_commits = {}
for commit in commits:
commit_date = datetime.strptime(commit['commit']['author']['date'], "%Y-%m-%dT%H:%M:%SZ")
month = commit_date.strftime("%Y-%m")
monthly_commits[month] = monthly_commits.get(month, ) +
return monthly_commits
workflow_configs = [
{"name": "test_workflow.yml", "content": "第一个工作流内容"},
{"name": "deploy_workflow.yml", "content": "第二个工作流内容"}
]
for config in workflow_configs:
octokit.rest.repos.create_or_update_file_contents(
owner=repo_owner,
repo=repo_name,
path=f".github/workflows/{config['name']}",
message=f"Add {config['name']}",
content=config['content'].encode("utf-8").hex(),
sha=get_existing_file_sha(octokit, repo_owner, repo_name, f".github/workflows/{config['name']}")
)
💬 让内容成为朋友圈的谈资,用户自然愿意分享平时大家刷朋友圈,那些能让一群人聊起来的内容,多半都藏着涨粉的机会。为啥?因为谁都想在社交圈里有点存在感,能抛出个有意思的话题,比发句 “今天天气真好”
公众号爆文的标题和封面,哪个对流量的影响更大?这个问题就像在问 “炒菜时盐和油哪个更重要”,看似对立,实则相辅相成。不过从实际运营数据来看,标题的重要性可能略胜一筹,但封面的作用也不容忽视。 标题是流
咱们今天好好唠唠 2025 年那些让人眼前一亮的 10w + 爆文,看看它们背后的选题策划思路到底有啥过人之处。这些爆文能火起来,可不是靠运气,而是有一套科学的方法。 先来说说选题策划这块。好多爆款文
很多企业把公众号交给第三方托管后,最头疼的就是怎么判断这笔钱花得值不值。有人盯着阅读量猛涨就觉得效果好,有人看到粉丝增速慢就认定托管没用 —— 其实这些都是片面的。真正的效果评估,得靠一套科学的量化体
🔍免费查重的原理是什么? 免费查重工具的核心是通过算法对比论文内容与数据库中的文献,识别重复片段。以 PaperPass 为例,它基于 transformer 的 attention 机制构建降重模
🔥 2025 最新 prompt 编写万能公式 | 助你轻松驾驭各类 AI 模型 2025 年的 AI 领域,模型更新速度简直像坐了火箭。就说 OpenAI 的 ChatGPT,虽然还在领跑,但 D
? 移动端访问 CMDW 游戏仓库的准备工作 玩游戏嘛,谁不想随时随地掏出手机就能开玩?尤其是像 CMDW 游戏仓库这种资源丰富的平台,移动端访问简直是刚需。不过,在开始之前,咱们得先把准备工作做好。
?数字化时代下,职场竞争的激烈程度早已不是简单的学历和经验比拼,而是综合能力与学习效率的全面较量。面对 2025 年职业生态的剧变,如何快速提升就业竞争力?今天就来聊聊职业全能培训库这个神器,看看它如