Skip to content

Commit 514dcff

Browse files
fix forgejo tests
1 parent de4de9a commit 514dcff

File tree

5 files changed

+204
-197
lines changed

5 files changed

+204
-197
lines changed

main.py

Lines changed: 192 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,192 @@
1-
import argparse
2-
import traceback
3-
4-
from src import commits_parser
5-
from src import contributors_parser
6-
from src import export_sheets
7-
from src import git_logger
8-
from src import invites_parser
9-
from src import issues_parser
10-
from src import pull_requests_parser
11-
from src import wikipars
12-
from src import workflow_runs_parser
13-
from src.utils import parse_time
14-
15-
16-
def parse_args():
17-
parser = argparse.ArgumentParser()
18-
parser.add_argument("--invites", help="print pending invites", action="store_true")
19-
parser.add_argument("-c", "--commits", help="log commits", action="store_true")
20-
parser.add_argument(
21-
"-p", "--pull_requests", help="log pull requests", action="store_true"
22-
)
23-
parser.add_argument("-i", "--issues", help="log issues", action="store_true")
24-
parser.add_argument("-w", "--wikis", help="log wikis", action="store_true")
25-
parser.add_argument("--contributors", help="log contributors", action="store_true")
26-
parser.add_argument(
27-
"--workflow_runs", help="log workflow runs", action="store_true"
28-
)
29-
parser.add_argument(
30-
"--forks_include", help="logging data from forks", action="store_true"
31-
)
32-
parser.add_argument(
33-
"-e",
34-
"--export_google_sheets",
35-
help="export table to google sheets",
36-
action="store_true",
37-
)
38-
39-
parser.add_argument(
40-
'--base_url',
41-
type=str,
42-
required=False,
43-
help='Base URL for Forgejo instance (if using Forgejo)',
44-
)
45-
46-
token = parser.add_mutually_exclusive_group(required=True)
47-
token.add_argument('-t', '--token', type=str, help='account access token')
48-
token.add_argument('--tokens', type=str, help='path to your tokens')
49-
50-
parser.add_argument(
51-
'-l',
52-
'--list',
53-
type=str,
54-
required=True,
55-
help=(
56-
'Path to the file containing the list of repositories. '
57-
'Repositories should be separated by a line break. '
58-
'Names should be in the format <organization or owner>/<name> '
59-
),
60-
)
61-
parser.add_argument(
62-
"--download_repos",
63-
type=str,
64-
help="path to downloaded repositories",
65-
default='./',
66-
)
67-
parser.add_argument('-o', '--out', type=str, required=True, help='output filename')
68-
parser.add_argument(
69-
"--pr_comments", help="log comments for PR", action="store_true"
70-
)
71-
parser.add_argument(
72-
'-s',
73-
'--start',
74-
type=str,
75-
required=False,
76-
help='start time',
77-
default='2000/01/01-00:00:00',
78-
)
79-
parser.add_argument(
80-
'-f',
81-
'--finish',
82-
type=str,
83-
required=False,
84-
help='finish time',
85-
default='2400/01/01-00:00:00',
86-
)
87-
parser.add_argument(
88-
'-b',
89-
'--branch',
90-
type=str,
91-
required=False,
92-
help=(
93-
'branch to select commits, '
94-
'by default use "default" repository branch, '
95-
'use "all" to get all commits from all branches',
96-
),
97-
default=None,
98-
)
99-
parser.add_argument(
100-
'--google_token',
101-
type=str,
102-
required=False,
103-
help='Specify path to google token file',
104-
)
105-
parser.add_argument(
106-
'--table_id',
107-
type=str,
108-
required=False,
109-
help='Specify Google sheet document id (can find in url)',
110-
)
111-
parser.add_argument(
112-
'--sheet_id',
113-
type=str,
114-
required=False,
115-
help='Specify title for a sheet in a document in which data will be printed',
116-
)
117-
args = parser.parse_args()
118-
119-
if args.export_google_sheets:
120-
for action in parser._actions:
121-
if action.dest == 'google_token':
122-
action.required = True
123-
if action.dest == 'table_id':
124-
action.required = True
125-
if action.dest == 'sheet_id':
126-
action.required = True
127-
return parser.parse_args()
128-
129-
130-
def run(args, binded_repos, repos_for_wiki=None):
131-
start = parse_time(args.start.split('-'))
132-
finish = parse_time(args.finish.split('-'))
133-
134-
if args.commits:
135-
commits_parser.log_commits(
136-
binded_repos, args.out, start, finish, args.branch, args.forks_include
137-
)
138-
if args.pull_requests:
139-
pull_requests_parser.log_pull_requests(
140-
binded_repos,
141-
args.out,
142-
start,
143-
finish,
144-
args.forks_include,
145-
args.pr_comments,
146-
)
147-
if args.issues:
148-
issues_parser.log_issues(
149-
binded_repos, args.out, start, finish, args.forks_include
150-
)
151-
if args.invites:
152-
invites_parser.log_invitations(
153-
binded_repos,
154-
args.out,
155-
)
156-
if args.contributors:
157-
contributors_parser.log_contributors(binded_repos, args.out, args.forks_include)
158-
if args.workflow_runs:
159-
workflow_runs_parser.log_workflow_runs(
160-
binded_repos, args.out, args.forks_include
161-
)
162-
if args.wikis:
163-
wikipars.wikiparser(repos_for_wiki, args.download_repos, args.out)
164-
if args.export_google_sheets:
165-
export_sheets.write_data_to_table(
166-
args.out, args.google_token, args.table_id, args.sheet_id
167-
)
168-
169-
170-
def main():
171-
args = parse_args()
172-
173-
if args.token:
174-
tokens = [args.token]
175-
else:
176-
tokens = git_logger.get_tokens_from_file(args.tokens)
177-
178-
repositories = git_logger.get_repos_from_file(args.list)
179-
180-
try:
181-
clients = git_logger.Clients(tokens, args.base_url)
182-
binded_repos = git_logger.get_next_binded_repo(clients, repositories)
183-
except Exception as e:
184-
print(f"Failed to initialize any clients: {e}")
185-
print(traceback.format_exc())
186-
return
187-
188-
run(args, binded_repos, repositories)
189-
190-
191-
if __name__ == '__main__':
192-
main()
1+
import argparse
2+
import traceback
3+
4+
from src import commits_parser
5+
from src import contributors_parser
6+
from src import export_sheets
7+
from src import git_logger
8+
from src import invites_parser
9+
from src import issues_parser
10+
from src import pull_requests_parser
11+
from src import wikipars
12+
from src import workflow_runs_parser
13+
from src.utils import parse_time
14+
15+
16+
def parse_args():
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("--invites", help="print pending invites", action="store_true")
19+
parser.add_argument("-c", "--commits", help="log commits", action="store_true")
20+
parser.add_argument(
21+
"-p", "--pull_requests", help="log pull requests", action="store_true"
22+
)
23+
parser.add_argument("-i", "--issues", help="log issues", action="store_true")
24+
parser.add_argument("-w", "--wikis", help="log wikis", action="store_true")
25+
parser.add_argument("--contributors", help="log contributors", action="store_true")
26+
parser.add_argument(
27+
"--workflow_runs", help="log workflow runs", action="store_true"
28+
)
29+
parser.add_argument(
30+
"--forks_include", help="logging data from forks", action="store_true"
31+
)
32+
parser.add_argument(
33+
"-e",
34+
"--export_google_sheets",
35+
help="export table to google sheets",
36+
action="store_true",
37+
)
38+
39+
parser.add_argument(
40+
'--base_url',
41+
type=str,
42+
required=False,
43+
help='Base URL for Forgejo instance (if using Forgejo)',
44+
)
45+
46+
token = parser.add_mutually_exclusive_group(required=True)
47+
token.add_argument('-t', '--token', type=str, help='account access token')
48+
token.add_argument('--tokens', type=str, help='path to your tokens')
49+
50+
parser.add_argument(
51+
'-l',
52+
'--list',
53+
type=str,
54+
required=True,
55+
help=(
56+
'Path to the file containing the list of repositories. '
57+
'Repositories should be separated by a line break. '
58+
'Names should be in the format <organization or owner>/<name> '
59+
),
60+
)
61+
parser.add_argument(
62+
"--download_repos",
63+
type=str,
64+
help="path to downloaded repositories",
65+
default='./',
66+
)
67+
parser.add_argument('-o', '--out', type=str, required=True, help='output filename')
68+
parser.add_argument(
69+
"--pr_comments", help="log comments for PR", action="store_true"
70+
)
71+
parser.add_argument(
72+
'-s',
73+
'--start',
74+
type=str,
75+
required=False,
76+
help='start time',
77+
default='2000/01/01-00:00:00',
78+
)
79+
parser.add_argument(
80+
'-f',
81+
'--finish',
82+
type=str,
83+
required=False,
84+
help='finish time',
85+
default='2400/01/01-00:00:00',
86+
)
87+
parser.add_argument(
88+
'-b',
89+
'--branch',
90+
type=str,
91+
required=False,
92+
help=(
93+
'branch to select commits, '
94+
'by default use "default" repository branch, '
95+
'use "all" to get all commits from all branches',
96+
),
97+
default=None,
98+
)
99+
parser.add_argument(
100+
'--google_token',
101+
type=str,
102+
required=False,
103+
help='Specify path to google token file',
104+
)
105+
parser.add_argument(
106+
'--table_id',
107+
type=str,
108+
required=False,
109+
help='Specify Google sheet document id (can find in url)',
110+
)
111+
parser.add_argument(
112+
'--sheet_id',
113+
type=str,
114+
required=False,
115+
help='Specify title for a sheet in a document in which data will be printed',
116+
)
117+
args = parser.parse_args()
118+
119+
if args.export_google_sheets:
120+
for action in parser._actions:
121+
if action.dest == 'google_token':
122+
action.required = True
123+
if action.dest == 'table_id':
124+
action.required = True
125+
if action.dest == 'sheet_id':
126+
action.required = True
127+
return parser.parse_args()
128+
129+
130+
def run(args, binded_repos, repos_for_wiki=None):
131+
start = parse_time(args.start.split('-'))
132+
finish = parse_time(args.finish.split('-'))
133+
134+
if args.commits:
135+
commits_parser.log_commits(
136+
binded_repos, args.out, start, finish, args.branch, args.forks_include
137+
)
138+
if args.pull_requests:
139+
pull_requests_parser.log_pull_requests(
140+
binded_repos,
141+
args.out,
142+
start,
143+
finish,
144+
args.forks_include,
145+
args.pr_comments,
146+
)
147+
if args.issues:
148+
issues_parser.log_issues(
149+
binded_repos, args.out, start, finish, args.forks_include, args.base_url,
150+
)
151+
if args.invites:
152+
invites_parser.log_invitations(
153+
binded_repos,
154+
args.out,
155+
)
156+
if args.contributors:
157+
contributors_parser.log_contributors(binded_repos, args.out, args.forks_include)
158+
if args.workflow_runs:
159+
workflow_runs_parser.log_workflow_runs(
160+
binded_repos, args.out, args.forks_include
161+
)
162+
if args.wikis:
163+
wikipars.wikiparser(repos_for_wiki, args.download_repos, args.out)
164+
if args.export_google_sheets:
165+
export_sheets.write_data_to_table(
166+
args.out, args.google_token, args.table_id, args.sheet_id
167+
)
168+
169+
170+
def main():
171+
args = parse_args()
172+
173+
if args.token:
174+
tokens = [args.token]
175+
else:
176+
tokens = git_logger.get_tokens_from_file(args.tokens)
177+
178+
repositories = git_logger.get_repos_from_file(args.list)
179+
180+
try:
181+
clients = git_logger.Clients(tokens, args.base_url)
182+
binded_repos = git_logger.get_next_binded_repo(clients, repositories)
183+
except Exception as e:
184+
print(f"Failed to initialize any clients: {e}")
185+
print(traceback.format_exc())
186+
return
187+
188+
run(args, binded_repos, repositories)
189+
190+
191+
if __name__ == '__main__':
192+
main()

src/ForgejoRepoAPI.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def get_issues(self, repo: Repository) -> list[Issue]:
101101
return [
102102
Issue(
103103
_id=i.id,
104+
number=i.number,
104105
title=i.title,
105106
state=i.state,
106107
created_at=i.created_at,

0 commit comments

Comments
 (0)