Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited76b12

Browse files
committed
[fix] black code formatting
1 parent78f96b2 commited76b12

File tree

3 files changed

+109
-59
lines changed

3 files changed

+109
-59
lines changed

‎.github/workflows/gha_clean.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python3 ./gh_workflow_runs_delete.py -d -r grindsa/github_actions_clean -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c 1
2424
-name:check a2c
2525
run:|
26-
python3 ./gh_workflow_runs_delete.py -d -r grindsa/acme2certifier -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c2
26+
python3 ./gh_workflow_runs_delete.py -d -r grindsa/acme2certifier -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c1
2727
-name:check est_proxy
2828
run:|
2929
python3 ./gh_workflow_runs_delete.py -d -r grindsa/est_proxy -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c 1
@@ -32,7 +32,7 @@ jobs:
3232
python3 ./gh_workflow_runs_delete.py -d -r grindsa/dkb-robo -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c 1
3333
-name:check grindsa/ncm-issuer
3434
run:|
35-
python3 ./gh_workflow_runs_delete.py -d -r grindsa/ncm-issuer -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c2
35+
python3 ./gh_workflow_runs_delete.py -d -r grindsa/ncm-issuer -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c1
3636
-name:check grindsa/sbom
3737
run:|
3838
python3 ./gh_workflow_runs_delete.py -d -r grindsa/sbom -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c 1
@@ -49,7 +49,7 @@ jobs:
4949
5050
-name:check grindsa/docker-pen
5151
run:|
52-
python3 ./gh_workflow_runs_delete.py -d -r grindsa/docker-pen -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c2
52+
python3 ./gh_workflow_runs_delete.py -d -r grindsa/docker-pen -t ${{ secrets.GH_TOKEN }} -u ${{ secrets.GH_USER }} -c1
5353
5454
-name:check nokia/ncm-issuer
5555
run:|

‎.pre-commit-config.yaml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
-repo:https://github.com/pre-commit/pre-commit-hooks
5+
rev:v3.2.0
6+
hooks:
7+
-id:trailing-whitespace
8+
-id:end-of-file-fixer
9+
-id:check-added-large-files
10+
-id:check-case-conflict
11+
-id:check-docstring-first
12+
-id:check-json
13+
-id:check-merge-conflict
14+
-id:check-symlinks
15+
-id:check-toml
16+
-id:check-xml
17+
-id:check-yaml
18+
args:[--allow-multiple-documents]
19+
-id:debug-statements
20+
# - id: double-quote-string-fixer
21+
-id:mixed-line-ending
22+
23+
-repo:https://github.com/psf/black
24+
rev:22.10.0
25+
hooks:
26+
-id:black

‎gh_workflow_runs_delete.py‎

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111

1212

1313
defarg_parse():
14-
""" simple argparser """
15-
parser=argparse.ArgumentParser(description='gh_workflow_runs_delete.py - delete github action logs and artifacts')
16-
parser.add_argument('-d','--debug',help='debug mode',action="store_true",default=False)
17-
parser.add_argument('-r','--reponame',help='repositoryname',default=None)
18-
parser.add_argument('-u','--username',help='username',default=None)
19-
parser.add_argument('-t','--token',help='token',default=None)
20-
parser.add_argument('-c','--commits',help='number of commits to keep',default=1)
21-
parser.add_argument('--branchlist',help='list of branches',default=False)
22-
parser.add_argument('-a','--delete-all',help='delete all logs',action="store_true",default=False)
14+
"""simple argparser"""
15+
parser=argparse.ArgumentParser(
16+
description="gh_workflow_runs_delete.py - delete github action logs and artifacts"
17+
)
18+
parser.add_argument(
19+
"-d","--debug",help="debug mode",action="store_true",default=False
20+
)
21+
parser.add_argument("-r","--reponame",help="repositoryname",default=None)
22+
parser.add_argument("-u","--username",help="username",default=None)
23+
parser.add_argument("-t","--token",help="token",default=None)
24+
parser.add_argument("-c","--commits",help="number of commits to keep",default=1)
25+
parser.add_argument("--branchlist",help="list of branches",default=False)
26+
parser.add_argument(
27+
"-a","--delete-all",help="delete all logs",action="store_true",default=False
28+
)
2329
args=parser.parse_args()
2430

2531
debug=args.debug
@@ -31,104 +37,122 @@ def arg_parse():
3137
auth=None
3238
delete_all=args.delete_all
3339
ifnotreponame:
34-
print('reponame (-r) is missing')
40+
print("reponame (-r) is missing")
3541
sys.exit(0)
3642
ifusernameandtoken:
3743
auth= (username,token)
3844
else:
39-
print('authentication incomplete (either user or token are missing)')
45+
print("authentication incomplete (either user or token are missing)")
4046
sys.exit(0)
4147

4248
return (debug,auth,reponame,branchlist,commit_num,delete_all)
4349

4450

4551
defbranchlist_get(debug,auth,reponame):
46-
"""get list of branches from github"""
47-
print_debug(debug,'branchlist_get()')
48-
branch_list= ['scheduled']
49-
url=f'https://api.github.com/repos/{reponame}/branches'
52+
"""get list of branches from github"""
53+
print_debug(debug,"branchlist_get()")
54+
branch_list= ["scheduled"]
55+
url=f"https://api.github.com/repos/{reponame}/branches"
5056
resp=requests.get(url=url,auth=auth,timeout=20)
5157
forbranchinresp.json():
52-
if'name'inbranch:
53-
branch_list.append(branch['name'])
58+
if"name"inbranch:
59+
branch_list.append(branch["name"])
5460

5561
returnbranch_list
5662

5763

5864
defwfruns_get(debug,auth,reponame):
59-
"""get list of runs"""
60-
print_debug(debug,'wfruns_get()')
65+
"""get list of runs"""
66+
print_debug(debug,"wfruns_get()")
6167
perpage=100
62-
url=f'https://api.github.com/repos/{reponame}/actions/runs?per_page={perpage}'
68+
url=f"https://api.github.com/repos/{reponame}/actions/runs?per_page={perpage}"
6369
resp=requests.get(url=url,auth=auth,timeout=20)
6470

6571
pagenum=0
66-
if'total_count'inresp.json():
67-
pagenum=math.ceil(resp.json()['total_count']/perpage)
68-
print_debug(debug,f'totalcount:{resp.json()["total_count"]}, perpage:{perpage}, pages:{pagenum}')
72+
if"total_count"inresp.json():
73+
pagenum=math.ceil(resp.json()["total_count"]/perpage)
74+
print_debug(
75+
debug,
76+
f'totalcount:{resp.json()["total_count"]}, perpage:{perpage}, pages:{pagenum}',
77+
)
6978

7079
workflow_list= []
7180
ifpagenum:
7281
foreleinrange(1,pagenum+1):
73-
print_debug(debug,f'fetching page:{ele}')
74-
url=f'https://api.github.com/repos/{reponame}/actions/runs?per_page={perpage}&page={ele}'
82+
print_debug(debug,f"fetching page:{ele}")
83+
url=f"https://api.github.com/repos/{reponame}/actions/runs?per_page={perpage}&page={ele}"
7584
resp=requests.get(url=url,auth=auth,timeout=20)
76-
if'workflow_runs'inresp.json():
77-
workflow_list.extend(resp.json()['workflow_runs'])
85+
if"workflow_runs"inresp.json():
86+
workflow_list.extend(resp.json()["workflow_runs"])
7887

7988
# json_store('ids.json', workflow_list)
8089
returnworkflow_list
8190

8291

8392
defwfruns_group(debug,action_list):
84-
"""group action list by branch"""
85-
print_debug(debug,'wfruns_group()')
86-
actions_dic= {'scheduled': {}}
93+
"""group action list by branch"""
94+
print_debug(debug,"wfruns_group()")
95+
actions_dic= {"scheduled": {}}
8796
forworkflowinaction_list:
88-
if'head_branch'inworkflowand'head_sha'inworkflowand'head_commit'inworkflowand'id'inworkflow:
89-
uts=int(calendar.timegm(parse(workflow['head_commit']['timestamp']).timetuple()))
97+
if (
98+
"head_branch"inworkflow
99+
and"head_sha"inworkflow
100+
and"head_commit"inworkflow
101+
and"id"inworkflow
102+
):
103+
uts=int(
104+
calendar.timegm(parse(workflow["head_commit"]["timestamp"]).timetuple())
105+
)
90106
# print(workflow['id'], workflow['head_branch'], workflow['head_sha'], workflow['head_commit']['timestamp'], uts)
91107
# add branchname to dictionary
92-
ifworkflow['head_branch']notinactions_dic:
93-
actions_dic[workflow['head_branch']]= {}
108+
ifworkflow["head_branch"]notinactions_dic:
109+
actions_dic[workflow["head_branch"]]= {}
94110

95-
ifworkflow['event']=='schedule':
111+
ifworkflow["event"]=="schedule":
96112
# special handling for scheduled workflows
97-
cdate,_junk=workflow['created_at'].split('T',1)
98-
ifcdatenotinactions_dic['scheduled']:
99-
actions_dic['scheduled'][cdate]= {'commit':workflow['head_sha'],'id_list': []}
100-
actions_dic['scheduled'][cdate]['id_list'].append(workflow['id'])
113+
cdate,_junk=workflow["created_at"].split("T",1)
114+
ifcdatenotinactions_dic["scheduled"]:
115+
actions_dic["scheduled"][cdate]= {
116+
"commit":workflow["head_sha"],
117+
"id_list": [],
118+
}
119+
actions_dic["scheduled"][cdate]["id_list"].append(workflow["id"])
101120
else:
102121
# add uts to branch-tree
103-
ifutsnotinactions_dic[workflow['head_branch']]:
104-
actions_dic[workflow['head_branch']][uts]= {'commit':workflow['head_sha'],'id_list': []}
105-
actions_dic[workflow['head_branch']][uts]['id_list'].append(workflow['id'])
122+
ifutsnotinactions_dic[workflow["head_branch"]]:
123+
actions_dic[workflow["head_branch"]][uts]= {
124+
"commit":workflow["head_sha"],
125+
"id_list": [],
126+
}
127+
actions_dic[workflow["head_branch"]][uts]["id_list"].append(
128+
workflow["id"]
129+
)
106130

107131
returnactions_dic
108132

109133

110134
defjson_load(file_name):
111-
"""load json structure from file"""
112-
withopen(file_name,encoding='utf8')asjson_file:
135+
"""load json structure from file"""
136+
withopen(file_name,encoding="utf8")asjson_file:
113137
data=json.load(json_file)
114138
returndata
115139

116140

117141
defjson_store(file_name_,data_):
118-
"""store structure as json to file"""
119-
withopen(file_name_,'w',encoding='utf-8')asout_file:
142+
"""store structure as json to file"""
143+
withopen(file_name_,"w",encoding="utf-8")asout_file:
120144
json.dump(data_,out_file,ensure_ascii=False,indent=4)
121145

122146

123147
defprint_debug(debug,text):
124-
"""little helper to print debug messages"""
148+
"""little helper to print debug messages"""
125149
ifdebug:
126-
print(f'{datetime.now()}:{text}')
150+
print(f"{datetime.now()}:{text}")
127151

128152

129153
defidlist_filter(debug,action_dic,branch_list,commit_number,delete_all):
130-
"""select ids to be deleted"""
131-
print_debug(debug,f'idlist_filter({commit_number})')
154+
"""select ids to be deleted"""
155+
print_debug(debug,f"idlist_filter({commit_number})")
132156
id_list= []
133157
forbranchinaction_dic:
134158
delete=False
@@ -140,22 +164,22 @@ def idlist_filter(debug, action_dic, branch_list, commit_number, delete_all):
140164
# skip latest n commits
141165
delete=True
142166
# print_debug(debug, '{0}, {1}, {2}, {3}'.format(branch, timestamp, idx, delete))
143-
forid_inaction_dic[branch][timestamp]['id_list']:
167+
forid_inaction_dic[branch][timestamp]["id_list"]:
144168
ifdelete:
145169
id_list.append(id_)
146170
returnid_list
147171

148172

149173
defidlist_delete(debug,auth,reponame,id_list):
150-
"""delete worflow logs"""
151-
print_debug(debug,f'idlist_delete({id_list})')
174+
"""delete worflow logs"""
175+
print_debug(debug,f"idlist_delete({id_list})")
152176
forid_inid_list:
153-
print_debug(debug,f'delete id:{id_}')
154-
url=f'https://api.github.com/repos/{reponame}/actions/runs/{id_}'
177+
print_debug(debug,f"delete id:{id_}")
178+
url=f"https://api.github.com/repos/{reponame}/actions/runs/{id_}"
155179
_resp=requests.delete(url=url,auth=auth,timeout=20)
156180

157181

158-
if__name__=='__main__':
182+
if__name__=="__main__":
159183

160184
(DEBUG,AUTH,REPONAME,BRANCHLIST,COMMIT_NUMBER,DELETE_ALL)=arg_parse()
161185

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp