gitcode-insight 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitcode_insight/__init__.py +24 -0
- gitcode_insight/cli.py +212 -0
- gitcode_insight/community.py +545 -0
- gitcode_insight/dashboard.py +522 -0
- gitcode_insight/issue.py +610 -0
- gitcode_insight/pr.py +843 -0
- gitcode_insight/repo_stats.py +883 -0
- gitcode_insight/report.py +1010 -0
- gitcode_insight/utils.py +113 -0
- gitcode_insight-0.1.0.dist-info/METADATA +103 -0
- gitcode_insight-0.1.0.dist-info/RECORD +15 -0
- gitcode_insight-0.1.0.dist-info/WHEEL +5 -0
- gitcode_insight-0.1.0.dist-info/entry_points.txt +2 -0
- gitcode_insight-0.1.0.dist-info/licenses/LICENSE +21 -0
- gitcode_insight-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
GitCode Insight - GitCode 平台代码洞察工具
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
__author__ = "GitCode Insight Team"
|
|
8
|
+
|
|
9
|
+
from .community import GitCodeCommunityStats
|
|
10
|
+
from .issue import GitCodeIssueInsight
|
|
11
|
+
from .pr import GitCodePRInsight
|
|
12
|
+
from .dashboard import generate_dashboard, generate_markdown_file
|
|
13
|
+
from .repo_stats import GitCodeRepoStats
|
|
14
|
+
from .report import GitCodeReport
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"GitCodeCommunityStats",
|
|
18
|
+
"GitCodeIssueInsight",
|
|
19
|
+
"GitCodePRInsight",
|
|
20
|
+
"generate_dashboard",
|
|
21
|
+
"generate_markdown_file",
|
|
22
|
+
"GitCodeRepoStats",
|
|
23
|
+
"GitCodeReport",
|
|
24
|
+
]
|
gitcode_insight/cli.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
GitCode Insight 命令行入口
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import os
|
|
8
|
+
import json
|
|
9
|
+
|
|
10
|
+
from .community import GitCodeCommunityStats
|
|
11
|
+
from .issue import GitCodeIssueInsight
|
|
12
|
+
from .pr import GitCodePRInsight
|
|
13
|
+
from .dashboard import generate_dashboard
|
|
14
|
+
from .repo_stats import GitCodeRepoStats
|
|
15
|
+
from .report import GitCodeReport
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_config_owner(config_file):
|
|
19
|
+
"""从配置文件获取 owner"""
|
|
20
|
+
if config_file is None:
|
|
21
|
+
config_file = os.path.join(os.getcwd(), "config", "gitcode.json")
|
|
22
|
+
|
|
23
|
+
if os.path.exists(config_file):
|
|
24
|
+
with open(config_file, 'r', encoding='utf-8') as f:
|
|
25
|
+
config = json.load(f)
|
|
26
|
+
return config.get("owner", "")
|
|
27
|
+
return ""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def cmd_community(args):
|
|
31
|
+
"""社区洞察命令"""
|
|
32
|
+
config_file = args.config
|
|
33
|
+
output_dir = args.output
|
|
34
|
+
|
|
35
|
+
# 创建统计实例
|
|
36
|
+
stats_crawler = GitCodeCommunityStats(config_file=config_file, output_dir=output_dir)
|
|
37
|
+
|
|
38
|
+
# 爬取社区的统计数据
|
|
39
|
+
stats = stats_crawler.crawl_community_stats()
|
|
40
|
+
|
|
41
|
+
# 生成报告
|
|
42
|
+
stats_crawler.generate_report(stats)
|
|
43
|
+
|
|
44
|
+
# 保存到CSV
|
|
45
|
+
stats_crawler.save_to_csv(stats)
|
|
46
|
+
|
|
47
|
+
# 保存详细数据到JSON
|
|
48
|
+
stats_crawler.save_to_json(stats)
|
|
49
|
+
|
|
50
|
+
print("\n\n数据爬取和分析完成!")
|
|
51
|
+
print("- 详细报告已打印到控制台")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def cmd_issue(args):
|
|
55
|
+
"""Issue 洞察命令"""
|
|
56
|
+
insight = GitCodeIssueInsight(
|
|
57
|
+
repo=args.repo,
|
|
58
|
+
token=args.token,
|
|
59
|
+
owner=args.owner,
|
|
60
|
+
days=args.days,
|
|
61
|
+
range_by=args.range_by,
|
|
62
|
+
output_dir=args.output
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
insight.run()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def cmd_pr(args):
|
|
69
|
+
"""PR 洞察命令"""
|
|
70
|
+
insight = GitCodePRInsight(
|
|
71
|
+
repo=args.repo,
|
|
72
|
+
token=args.token,
|
|
73
|
+
owner=args.owner,
|
|
74
|
+
days=args.days,
|
|
75
|
+
output_dir=args.output
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
insight.run()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def cmd_repo_stats(args):
|
|
82
|
+
"""仓库统计命令"""
|
|
83
|
+
stats = GitCodeRepoStats(
|
|
84
|
+
repo=args.repo,
|
|
85
|
+
token=args.token,
|
|
86
|
+
owner=args.owner,
|
|
87
|
+
days=args.days,
|
|
88
|
+
output_dir=args.output
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
stats.run()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def cmd_dashboard(args):
|
|
95
|
+
"""生成看板命令(自动检测数据是否存在,不存在则先采集)"""
|
|
96
|
+
config_file = args.config
|
|
97
|
+
output_dir = args.output
|
|
98
|
+
|
|
99
|
+
# 设置默认路径
|
|
100
|
+
if config_file is None:
|
|
101
|
+
config_file = os.path.join(os.getcwd(), "config", "gitcode.json")
|
|
102
|
+
if output_dir is None:
|
|
103
|
+
output_dir = os.path.join(os.getcwd(), "output")
|
|
104
|
+
|
|
105
|
+
# 获取 owner
|
|
106
|
+
owner = get_config_owner(config_file)
|
|
107
|
+
if not owner:
|
|
108
|
+
print("错误: 无法从配置文件获取 owner")
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
# 检测数据文件是否存在
|
|
112
|
+
json_file = os.path.join(output_dir, f"{owner}_community_stats_detailed.json")
|
|
113
|
+
|
|
114
|
+
if not os.path.exists(json_file):
|
|
115
|
+
print(f"数据文件不存在: {json_file}")
|
|
116
|
+
print("开始自动采集数据...\n")
|
|
117
|
+
|
|
118
|
+
# 自动运行采集
|
|
119
|
+
stats_crawler = GitCodeCommunityStats(config_file=config_file, output_dir=output_dir)
|
|
120
|
+
stats = stats_crawler.crawl_community_stats()
|
|
121
|
+
stats_crawler.generate_report(stats)
|
|
122
|
+
stats_crawler.save_to_csv(stats)
|
|
123
|
+
stats_crawler.save_to_json(stats)
|
|
124
|
+
|
|
125
|
+
print("\n数据采集完成!\n")
|
|
126
|
+
|
|
127
|
+
# 生成看板
|
|
128
|
+
generate_dashboard(config_file=config_file, output_dir=output_dir)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def cmd_report(args):
|
|
132
|
+
"""仓库综合报告命令"""
|
|
133
|
+
report = GitCodeReport(
|
|
134
|
+
repo=args.repo,
|
|
135
|
+
token=args.token,
|
|
136
|
+
owner=args.owner,
|
|
137
|
+
days=args.days,
|
|
138
|
+
output_dir=args.output
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
report.run()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def main():
|
|
145
|
+
"""主入口"""
|
|
146
|
+
parser = argparse.ArgumentParser(
|
|
147
|
+
prog="gc-insight",
|
|
148
|
+
description="GitCode 平台代码洞察工具"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
subparsers = parser.add_subparsers(dest="command", help="子命令")
|
|
152
|
+
|
|
153
|
+
# community 子命令
|
|
154
|
+
community_parser = subparsers.add_parser("community", help="社区洞察")
|
|
155
|
+
community_parser.add_argument("--config", default=None, help="配置文件路径,默认使用 ./config/gitcode.json")
|
|
156
|
+
community_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
157
|
+
community_parser.set_defaults(func=cmd_community)
|
|
158
|
+
|
|
159
|
+
# issue 子命令
|
|
160
|
+
issue_parser = subparsers.add_parser("issue", help="Issue 洞察")
|
|
161
|
+
issue_parser.add_argument("--repo", required=True, help="仓库名称(path)")
|
|
162
|
+
issue_parser.add_argument("--token", required=True, help="API 访问令牌")
|
|
163
|
+
issue_parser.add_argument("--days", type=int, default=30, help="统计天数,默认 30")
|
|
164
|
+
issue_parser.add_argument("--range-by", dest="range_by", choices=["created", "updated", "active"], default="created", help="统计范围口径:created=近N天创建,updated=近N天更新,active=近N天创建或更新(默认 created)")
|
|
165
|
+
issue_parser.add_argument("--owner", default=None, help="组织名,默认从配置文件读取")
|
|
166
|
+
issue_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
167
|
+
issue_parser.set_defaults(func=cmd_issue)
|
|
168
|
+
|
|
169
|
+
# pr 子命令
|
|
170
|
+
pr_parser = subparsers.add_parser("pr", help="PR 洞察")
|
|
171
|
+
pr_parser.add_argument("--repo", required=True, help="仓库名称(path)")
|
|
172
|
+
pr_parser.add_argument("--token", required=True, help="API 访问令牌")
|
|
173
|
+
pr_parser.add_argument("--days", type=int, default=30, help="统计天数,默认 30")
|
|
174
|
+
pr_parser.add_argument("--owner", default=None, help="组织名,默认从配置文件读取")
|
|
175
|
+
pr_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
176
|
+
pr_parser.set_defaults(func=cmd_pr)
|
|
177
|
+
|
|
178
|
+
# repo-stats 子命令
|
|
179
|
+
repo_stats_parser = subparsers.add_parser("repo-stats", help="仓库统计")
|
|
180
|
+
repo_stats_parser.add_argument("--repo", required=True, help="仓库名称(path)")
|
|
181
|
+
repo_stats_parser.add_argument("--token", required=True, help="API 访问令牌")
|
|
182
|
+
repo_stats_parser.add_argument("--owner", default=None, help="组织名,默认从配置文件读取")
|
|
183
|
+
repo_stats_parser.add_argument("--days", type=int, default=30, help="统计天数,默认 30")
|
|
184
|
+
repo_stats_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
185
|
+
repo_stats_parser.set_defaults(func=cmd_repo_stats)
|
|
186
|
+
|
|
187
|
+
# dashboard 子命令
|
|
188
|
+
dashboard_parser = subparsers.add_parser("dashboard", help="生成看板")
|
|
189
|
+
dashboard_parser.add_argument("--config", default=None, help="配置文件路径,默认使用 ./config/gitcode.json")
|
|
190
|
+
dashboard_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
191
|
+
dashboard_parser.set_defaults(func=cmd_dashboard)
|
|
192
|
+
|
|
193
|
+
# report 子命令
|
|
194
|
+
report_parser = subparsers.add_parser("report", help="仓库综合报告")
|
|
195
|
+
report_parser.add_argument("--repo", required=True, help="仓库名称(path)")
|
|
196
|
+
report_parser.add_argument("--token", required=True, help="API 访问令牌")
|
|
197
|
+
report_parser.add_argument("--days", type=int, default=30, help="统计天数,默认 30")
|
|
198
|
+
report_parser.add_argument("--owner", default=None, help="组织名,默认从配置文件读取")
|
|
199
|
+
report_parser.add_argument("--output", default=None, help="输出目录,默认使用 ./output/")
|
|
200
|
+
report_parser.set_defaults(func=cmd_report)
|
|
201
|
+
|
|
202
|
+
args = parser.parse_args()
|
|
203
|
+
|
|
204
|
+
if args.command is None:
|
|
205
|
+
parser.print_help()
|
|
206
|
+
return
|
|
207
|
+
|
|
208
|
+
args.func(args)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
if __name__ == "__main__":
|
|
212
|
+
main()
|