gitcode-insight 0.1.0__tar.gz

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.
Files changed (28) hide show
  1. gitcode_insight-0.1.0/LICENSE +21 -0
  2. gitcode_insight-0.1.0/PKG-INFO +103 -0
  3. gitcode_insight-0.1.0/README.md +77 -0
  4. gitcode_insight-0.1.0/pyproject.toml +53 -0
  5. gitcode_insight-0.1.0/setup.cfg +4 -0
  6. gitcode_insight-0.1.0/src/gitcode_insight/__init__.py +24 -0
  7. gitcode_insight-0.1.0/src/gitcode_insight/cli.py +212 -0
  8. gitcode_insight-0.1.0/src/gitcode_insight/community.py +545 -0
  9. gitcode_insight-0.1.0/src/gitcode_insight/dashboard.py +522 -0
  10. gitcode_insight-0.1.0/src/gitcode_insight/issue.py +610 -0
  11. gitcode_insight-0.1.0/src/gitcode_insight/pr.py +843 -0
  12. gitcode_insight-0.1.0/src/gitcode_insight/repo_stats.py +883 -0
  13. gitcode_insight-0.1.0/src/gitcode_insight/report.py +1010 -0
  14. gitcode_insight-0.1.0/src/gitcode_insight/utils.py +113 -0
  15. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/PKG-INFO +103 -0
  16. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/SOURCES.txt +26 -0
  17. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/dependency_links.txt +1 -0
  18. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/entry_points.txt +2 -0
  19. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/requires.txt +5 -0
  20. gitcode_insight-0.1.0/src/gitcode_insight.egg-info/top_level.txt +1 -0
  21. gitcode_insight-0.1.0/tests/test_cli.py +271 -0
  22. gitcode_insight-0.1.0/tests/test_community.py +284 -0
  23. gitcode_insight-0.1.0/tests/test_dashboard.py +250 -0
  24. gitcode_insight-0.1.0/tests/test_issue.py +481 -0
  25. gitcode_insight-0.1.0/tests/test_pr.py +487 -0
  26. gitcode_insight-0.1.0/tests/test_repo_stats.py +218 -0
  27. gitcode_insight-0.1.0/tests/test_report.py +324 -0
  28. gitcode_insight-0.1.0/tests/test_utils.py +191 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GitCode Insight Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.4
2
+ Name: gitcode-insight
3
+ Version: 0.1.0
4
+ Summary: GitCode 平台代码洞察工具
5
+ Author: GitCode Insight Team
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://gitcode.com/gitcode-cli/insight
8
+ Project-URL: Repository, https://gitcode.com/gitcode-cli/insight
9
+ Keywords: gitcode,insight,analytics,dashboard
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Requires-Python: >=3.7
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests>=2.25.0
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest>=7.0.0; extra == "test"
24
+ Requires-Dist: pytest-cov>=4.0.0; extra == "test"
25
+ Dynamic: license-file
26
+
27
+ # GitCode Insight
28
+
29
+ [![Python Version](https://img.shields.io/badge/python-3.7%2B-blue.svg)](https://www.python.org/downloads/)
30
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
31
+
32
+ GitCode 平台代码洞察命令行工具,支持社区洞察、Issue/PR 分析、仓库统计,生成可视化报告。
33
+
34
+ ## 功能
35
+
36
+ | 功能 | 说明 |
37
+ |------|------|
38
+ | 社区洞察 | 分析组织下所有仓库的统计数据,生成看板 |
39
+ | Issue 洞察 | Issue 数量、响应时间、关闭率、标签分布 |
40
+ | PR 洞察 | 评审效率、合并耗时、变更规模、冲突率 |
41
+ | 仓库统计 | 下载量、Fork、订阅用户、编程语言 |
42
+ | 综合报告 | 整合所有模块的一站式报告 |
43
+
44
+ ## 快速开始
45
+
46
+ ```bash
47
+ # 安装
48
+ pip install gitcode-insight
49
+
50
+ # 或从源码安装
51
+ git clone https://gitcode.com/gitcode-cli/insight.git
52
+ cd insight
53
+ python3 -m venv .venv
54
+ .venv/bin/pip install -e ".[test]"
55
+
56
+ # 创建配置文件
57
+ cp config/gitcode.json.example config/gitcode.json
58
+ # 编辑配置文件,填入 access_token 和 owner
59
+
60
+ # 生成社区看板
61
+ gc-insight dashboard
62
+
63
+ # 分析单个仓库
64
+ gc-insight issue --repo your-repo --token your_token --days 30
65
+ gc-insight pr --repo your-repo --token your_token --days 30
66
+ gc-insight repo-stats --repo your-repo --token your_token --days 30
67
+ gc-insight report --repo your-repo --token your_token --days 30
68
+ ```
69
+
70
+ ## 配置
71
+
72
+ 配置文件 `config/gitcode.json`:
73
+
74
+ ```json
75
+ {
76
+ "access_token": "your_gitcode_access_token",
77
+ "owner": "your_organization_name"
78
+ }
79
+ ```
80
+
81
+ 获取 Access Token:GitCode → 设置 → 访问令牌 → 创建新令牌
82
+
83
+ ## 常见问题
84
+
85
+ **Q: 输出文件在哪里?**
86
+ A: 默认保存在 `./output/` 目录。
87
+
88
+ **Q: 请求频繁失败怎么办?**
89
+ A: GitCode API 每分钟限制 100 次请求,工具已内置限流处理。如遇问题,等待几分钟后重试。
90
+
91
+ **Q: CSV 文件中文乱码?**
92
+ A: 文件使用 UTF-8-BOM 编码,Excel 可正常打开。
93
+
94
+ ## 文档
95
+
96
+ - [用户指南](doc/user_guide.md) - 详细的安装配置和命令说明
97
+ - [开发指南](doc/development.md) - 本地开发和测试
98
+ - [贡献指南](CONTRIBUTING.md) - 参与项目贡献
99
+ - [API 文档](doc/gitcode_api/) - GitCode API 接口说明
100
+
101
+ ## 许可证
102
+
103
+ [MIT License](LICENSE)
@@ -0,0 +1,77 @@
1
+ # GitCode Insight
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.7%2B-blue.svg)](https://www.python.org/downloads/)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
+
6
+ GitCode 平台代码洞察命令行工具,支持社区洞察、Issue/PR 分析、仓库统计,生成可视化报告。
7
+
8
+ ## 功能
9
+
10
+ | 功能 | 说明 |
11
+ |------|------|
12
+ | 社区洞察 | 分析组织下所有仓库的统计数据,生成看板 |
13
+ | Issue 洞察 | Issue 数量、响应时间、关闭率、标签分布 |
14
+ | PR 洞察 | 评审效率、合并耗时、变更规模、冲突率 |
15
+ | 仓库统计 | 下载量、Fork、订阅用户、编程语言 |
16
+ | 综合报告 | 整合所有模块的一站式报告 |
17
+
18
+ ## 快速开始
19
+
20
+ ```bash
21
+ # 安装
22
+ pip install gitcode-insight
23
+
24
+ # 或从源码安装
25
+ git clone https://gitcode.com/gitcode-cli/insight.git
26
+ cd insight
27
+ python3 -m venv .venv
28
+ .venv/bin/pip install -e ".[test]"
29
+
30
+ # 创建配置文件
31
+ cp config/gitcode.json.example config/gitcode.json
32
+ # 编辑配置文件,填入 access_token 和 owner
33
+
34
+ # 生成社区看板
35
+ gc-insight dashboard
36
+
37
+ # 分析单个仓库
38
+ gc-insight issue --repo your-repo --token your_token --days 30
39
+ gc-insight pr --repo your-repo --token your_token --days 30
40
+ gc-insight repo-stats --repo your-repo --token your_token --days 30
41
+ gc-insight report --repo your-repo --token your_token --days 30
42
+ ```
43
+
44
+ ## 配置
45
+
46
+ 配置文件 `config/gitcode.json`:
47
+
48
+ ```json
49
+ {
50
+ "access_token": "your_gitcode_access_token",
51
+ "owner": "your_organization_name"
52
+ }
53
+ ```
54
+
55
+ 获取 Access Token:GitCode → 设置 → 访问令牌 → 创建新令牌
56
+
57
+ ## 常见问题
58
+
59
+ **Q: 输出文件在哪里?**
60
+ A: 默认保存在 `./output/` 目录。
61
+
62
+ **Q: 请求频繁失败怎么办?**
63
+ A: GitCode API 每分钟限制 100 次请求,工具已内置限流处理。如遇问题,等待几分钟后重试。
64
+
65
+ **Q: CSV 文件中文乱码?**
66
+ A: 文件使用 UTF-8-BOM 编码,Excel 可正常打开。
67
+
68
+ ## 文档
69
+
70
+ - [用户指南](doc/user_guide.md) - 详细的安装配置和命令说明
71
+ - [开发指南](doc/development.md) - 本地开发和测试
72
+ - [贡献指南](CONTRIBUTING.md) - 参与项目贡献
73
+ - [API 文档](doc/gitcode_api/) - GitCode API 接口说明
74
+
75
+ ## 许可证
76
+
77
+ [MIT License](LICENSE)
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gitcode-insight"
7
+ version = "0.1.0"
8
+ description = "GitCode 平台代码洞察工具"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.7"
12
+ authors = [
13
+ {name = "GitCode Insight Team"}
14
+ ]
15
+ keywords = ["gitcode", "insight", "analytics", "dashboard"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.7",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ ]
26
+ dependencies = [
27
+ "requests>=2.25.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ test = [
32
+ "pytest>=7.0.0",
33
+ "pytest-cov>=4.0.0",
34
+ ]
35
+
36
+ [project.scripts]
37
+ gc-insight = "gitcode_insight.cli:main"
38
+
39
+ [project.urls]
40
+ Homepage = "https://gitcode.com/gitcode-cli/insight"
41
+ Repository = "https://gitcode.com/gitcode-cli/insight"
42
+
43
+ [tool.setuptools.packages.find]
44
+ where = ["src"]
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+ python_files = ["test_*.py"]
49
+ python_functions = ["test_*"]
50
+ addopts = "-v --tb=short"
51
+ markers = [
52
+ "integration: marks tests that require real API access (deselect with '-m \"not integration\"')",
53
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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
+ ]
@@ -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()