Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Gepetto
dashboard
Commits
6a31804c
Commit
6a31804c
authored
Feb 09, 2018
by
Guilhem Saurel
Browse files
move travis stuff into models
parent
7e2c5eaa
Changes
3
Hide whitespace changes
Inline
Side-by-side
rainboard/management/commands/populate.py
View file @
6a31804c
...
...
@@ -34,5 +34,3 @@ class Command(BaseCommand):
call_command
(
'fetch'
)
call_command
(
'robotpkg'
)
call_command
(
'cmake'
)
call_command
(
'travis'
)
call_command
(
'delete_perso'
)
rainboard/management/commands/travis.py
deleted
100644 → 0
View file @
7e2c5eaa
import
logging
import
os
from
django.core.management.base
import
BaseCommand
from
rainboard.models
import
SOURCES
,
Forge
,
Namespace
,
Project
,
Repo
logger
=
logging
.
getLogger
(
'rainboard.management.travis'
)
GITHUB
=
Forge
.
objects
.
get
(
source
=
SOURCES
.
github
)
def
update_travis_id
(
data
):
namespace
,
project
=
data
[
'slug'
].
lower
().
split
(
'/'
)
namespace
=
Namespace
.
objects
.
get
(
slug
=
namespace
)
project
,
_
=
Project
.
objects
.
get_or_create
(
name
=
data
[
'name'
],
defaults
=
{
'main_namespace'
:
namespace
})
repo
,
created
=
Repo
.
objects
.
get_or_create
(
forge
=
GITHUB
,
namespace
=
namespace
,
project
=
project
,
defaults
=
{
'name'
:
data
[
'name'
],
'repo_id'
:
0
,
'travis_id'
:
data
[
'id'
]})
if
created
:
repo
.
api_update
()
else
:
repo
.
travis_id
=
data
[
'id'
]
repo
.
save
()
class
Command
(
BaseCommand
):
help
=
'Gets Repo.travis_id'
def
handle
(
self
,
*
args
,
**
options
):
logger
.
info
(
'Adding Travis Forge if needed'
)
travis
=
Forge
.
objects
.
get
(
source
=
SOURCES
.
travis
)
logger
.
info
(
'Gettings travis_id'
)
for
namespace
in
Namespace
.
objects
.
all
():
logger
.
info
(
f
' Gettings travis_id for
{
namespace
}
'
)
next_url
=
f
'/owner/
{
namespace
.
slug
}
/repos'
data
=
travis
.
api_data
(
next_url
)
if
not
data
or
data
[
'@type'
]
!=
'repositories'
:
continue
while
True
:
for
repository
in
data
[
'repositories'
]:
if
repository
[
'active'
]:
logger
.
info
(
' update travis id for '
+
repository
[
'slug'
])
update_travis_id
(
repository
)
if
data
[
'@pagination'
][
'next'
]
is
None
:
break
next_url
=
data
[
'@pagination'
][
'next'
][
'@href'
]
data
=
travis
.
api_data
(
next_url
)
rainboard/models.py
View file @
6a31804c
...
...
@@ -114,6 +114,9 @@ class Forge(Links, NamedModel):
def
get_namespaces_redmine
(
self
):
pass
# TODO
def
get_namespaces_travis
(
self
):
pass
def
get_projects
(
self
):
getattr
(
self
,
f
'get_namespaces_
{
self
.
get_source_display
()
}
'
)()
return
getattr
(
self
,
f
'get_projects_
{
self
.
get_source_display
()
}
'
)()
...
...
@@ -138,6 +141,12 @@ class Forge(Links, NamedModel):
def
get_projects_redmine
(
self
):
pass
# TODO
def
get_projects_travis
(
self
):
for
namespace
in
Namespace
.
objects
.
all
():
for
repository
in
self
.
api_list
(
f
'/owner/
{
namespace
.
slug
}
/repos'
,
'repositories'
):
if
repository
[
'active'
]:
update_travis
(
namespace
,
repository
)
class
Project
(
Links
,
NamedModel
,
TimeStampedModel
):
private
=
models
.
BooleanField
(
default
=
False
)
...
...
@@ -299,7 +308,10 @@ class Repo(TimeStampedModel):
return
[]
# TODO
data
=
req
.
json
()
if
name
is
not
None
:
data
=
data
[
name
]
if
name
in
data
:
data
=
data
[
name
]
else
:
return
[]
# TODO
yield
from
data
page
=
api_next
(
self
.
forge
.
source
,
req
)
...
...
@@ -635,3 +647,17 @@ def update_github(forge, namespace, data):
repo
.
open_pr
=
len
(
list
(
repo
.
api_list
(
'/pulls'
)))
repo
.
save
()
project
.
save
()
def
update_travis
(
namespace
,
data
):
project
=
Project
.
objects
.
filter
(
name
=
data
[
'name'
]).
first
()
if
project
is
None
:
return
forge
=
Forge
.
objects
.
get
(
source
=
SOURCES
.
github
)
repo
,
created
=
Repo
.
objects
.
get_or_create
(
forge
=
forge
,
namespace
=
namespace
,
project
=
project
,
defaults
=
{
'name'
:
data
[
'name'
],
'repo_id'
:
0
,
'travis_id'
:
data
[
'id'
]})
if
created
:
repo
.
api_update
()
else
:
repo
.
travis_id
=
data
[
'id'
]
repo
.
save
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment