Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60727600
deactivate_empty_repo.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, May 2, 05:50
Size
1 KB
Mime Type
text/x-python
Expires
Sat, May 4, 05:50 (2 d)
Engine
blob
Format
Raw Data
Handle
17274322
Attached To
rPHINFRA c4science
deactivate_empty_repo.py
View Options
#!/usr/bin/env python3
from
phabricator
import
Phabricator
import
arrow
date_before
=
arrow
.
get
()
.
shift
(
months
=-
6
)
phab
=
Phabricator
(
host
=
'https://c4science.ch/api/'
)
phab
.
update_interfaces
()
def
get_repos
(
after
):
return
phab
.
diffusion
.
repository
.
search
(
after
=
after
,
order
=
"oldest"
,
)
number
=
0
total
=
0
after
=
0
while
after
!=
None
:
repo
=
get_repos
(
after
)
after
=
repo
[
'cursor'
][
'after'
]
for
r
in
repo
[
'data'
]:
phid
=
r
[
'phid'
]
name
=
r
[
'fields'
][
'name'
]
date
=
arrow
.
get
(
r
[
'fields'
][
'dateCreated'
])
status
=
r
[
'fields'
][
'status'
]
url
=
'https://c4science.ch/diffusion/{_id}/'
.
format
(
_id
=
r
[
'id'
])
if
r
[
'id'
]
in
[
3516
,
3518
]
or
r
[
'id'
]
<
5769
:
continue
print
(
'R{_id} {name} {url} {created}'
.
format
(
_id
=
r
[
'id'
],
name
=
name
,
url
=
url
,
created
=
date
.
humanize
()))
commits
=
phab
.
diffusion
.
commit
.
search
(
limit
=
1
,
constraints
=
{
"repositories"
:
[
phid
],
},
)
if
len
(
commits
[
'data'
])
==
0
:
if
status
==
'active'
:
total
+=
1
if
date
<
date_before
:
number
+=
1
phab
.
diffusion
.
repository
.
edit
(
objectIdentifier
=
phid
,
transactions
=
[
{
'type'
:
'status'
,
'value'
:
'inactive'
},
],
)
print
(
'Deactivated {}'
.
format
(
phid
))
print
(
'Total {} empty repositories'
.
format
(
total
))
print
(
'Deactivated {} repositories'
.
format
(
number
))
Event Timeline
Log In to Comment