Skip to content

Commit 586ff2a

Browse files
committed
Initiail commit for Repo Score v2
The Repo Score v1 is forked from criticality_score and had much not graceful modification on upstream code, after the discussion[1], we decided to decouple the dependency of criticality_score. So in this patch, we keep the v1 code and doc unchanged, only move the criticality_score into requirements, set the setup version to 2.0.0 to avoid the pypi reupload problem[2]. [1] #1 [2] pypa/packaging-problems#74 Close: #1
1 parent 5e81ddd commit 586ff2a

File tree

7 files changed

+185
-1
lines changed

7 files changed

+185
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright [2021] [Repo Score Author]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## 项目说明
2+
给github和gitlab上面的工程评分, 基于[criticality_score](https://github.com/ossf/criticality_score),增加了批量统计的功能
3+
4+
## 使用方法
5+
设置GitHub Token:
6+
- 如果你还没有Token,[创建一个Github Token](https://docs.github.com/en/free-pro-team@latest/developers/apps/about-apps#personal-access-tokens)
7+
,设置环境变量 `GITHUB_AUTH_TOKEN`.
8+
这样可以避免Github的[api用量限制](https://developer.github.com/v3/#rate-limiting)
9+
10+
```shell
11+
export GITHUB_AUTH_TOKEN=<your access token>
12+
```
13+
如果你统计的项目里有GitLab的项目,还需要设置GitLab的Token:
14+
- 如果你还没有,[创建一个Gitlab Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html)
15+
,设置环境变量 `GITLAB_AUTH_TOKEN`.
16+
17+
准备工程的url列表文件,一行一个url, 格式可以参考本项目reposcore目录下的projects.txt文件
18+
19+
```shell
20+
pip3 uninstall python-gitlab PyGithub
21+
pip3 install python-gitlab PyGithub
22+
git clone https://github.com/kunpengcompute/reposcore
23+
cd reposcore
24+
python3 setup.py install
25+
reposcore --projects_list projects_url_file --result_file result.csv
26+
```
27+
28+
最终输出为csv格式的文件
29+
30+
## Project Description
31+
Score github or gitlab's projects, based on [criticality_score](https://github.com/ossf/criticality_score), added batch function.
32+
## Usage
33+
Before running, you need to:
34+
35+
For GitHub repos, you need to [create a GitHub access token](https://docs.github.com/en/free-pro-team@latest/developers/apps/about-apps#personal-access-tokens) and set it in environment variable `GITHUB_AUTH_TOKEN`.
36+
```shell
37+
export GITHUB_AUTH_TOKEN=<your access token>
38+
```
39+
For GitLab repos, you need to [create a GitLab access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) and set it in environment variable `GITLAB_AUTH_TOKEN`.
40+
41+
42+
Prepare a projects url file, one url per line, please refer to projects.txt under directory reposcore.
43+
```shell
44+
pip3 uninstall python-gitlab PyGithub
45+
pip3 install python-gitlab PyGithub
46+
git clone https://github.com/kunpengcompute/reposcore
47+
cd reposcore
48+
python3 setup.py install
49+
reposcore --projects_list projects_url_file --result_file result.csv
50+
```
51+
The final output is a csv format file.
52+

reposcore/__init__.py

Whitespace-only changes.

reposcore/projects.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://github.com/kubernetes/kubernetes
2+
https://github.com/tensorflow/tensorflow

reposcore/reposcore.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""Main python script for calculating OSS Criticality Score."""
13+
14+
import argparse
15+
import csv
16+
import os
17+
import sys
18+
import time
19+
20+
from criticality_score import run
21+
22+
23+
def init_constants():
24+
# See more constants in:
25+
# https://github.com/ossf/criticality_score/blob/main/criticality_score/constants.py
26+
run.CONTRIBUTOR_COUNT_WEIGHT = 1
27+
run.ORG_COUNT_WEIGHT = 0.5
28+
run.COMMIT_FREQUENCY_WEIGHT = 4
29+
run.COMMENT_FREQUENCY_WEIGHT = 0.5
30+
run.DEPENDENTS_COUNT_WEIGHT = 1
31+
32+
33+
def main():
34+
init_constants()
35+
parser = argparse.ArgumentParser(
36+
description=
37+
'Generate a sorted criticality score list for input projects .')
38+
parser.add_argument("--projects_list",
39+
type=open,
40+
required=True,
41+
help="File name of projects url list.")
42+
parser.add_argument("--result_file",
43+
type=str,
44+
required=True,
45+
help="Result file name.")
46+
47+
args = parser.parse_args()
48+
49+
repo_urls = set()
50+
repo_urls.update(args.projects_list.read().splitlines())
51+
52+
csv_writer = csv.writer(sys.stdout)
53+
header = None
54+
stats = []
55+
for repo_url in repo_urls:
56+
output = None
57+
for _ in range(3):
58+
try:
59+
repo = run.get_repository(repo_url)
60+
output = run.get_repository_stats(repo)
61+
break
62+
except Exception as exp:
63+
print(
64+
f'Exception occurred when reading repo: {repo_url}\n{exp}')
65+
if not output:
66+
continue
67+
if not header:
68+
header = output.keys()
69+
csv_writer.writerow(header)
70+
csv_writer.writerow(output.values())
71+
stats.append(output)
72+
73+
with open(args.result_file, 'w') as file_handle:
74+
csv_writer = csv.writer(file_handle)
75+
csv_writer.writerow(header)
76+
for i in sorted(stats,
77+
key=lambda i: i['criticality_score'],
78+
reverse=True):
79+
csv_writer.writerow(i.values())
80+
print(f'Wrote results: {args.result_file}')
81+
82+
83+
if __name__ == "__main__":
84+
main()
85+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
criticality_score

setup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""setup.py for Repo Score projects"""
13+
import setuptools
14+
15+
with open('README.md', 'r') as fh:
16+
long_description = fh.read()
17+
18+
setuptools.setup(
19+
name='reposcore',
20+
version='2.0.0',
21+
author='KunpengCompute',
22+
author_email='',
23+
description='Gives scores for open source projects',
24+
long_description=long_description,
25+
long_description_content_type='text/markdown',
26+
url='https://github.com/kunpengcompute/reposcore',
27+
packages=setuptools.find_packages(),
28+
classifiers=[
29+
'Programming Language :: Python :: 3',
30+
'License :: OSI Approved :: Apache Software License',
31+
'Operating System :: OS Independent',
32+
],
33+
install_requires=[
34+
'criticality_score',
35+
'PyGithub>=1.53',
36+
'python-gitlab>=2.5.0',
37+
],
38+
entry_points={
39+
'console_scripts': ['reposcore=reposcore.reposcore:main'],
40+
},
41+
python_requires='>=3',
42+
zip_safe=False,
43+
)
44+

0 commit comments

Comments
 (0)