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
0b60d576
Commit
0b60d576
authored
Feb 05, 2018
by
Guilhem Saurel
Browse files
branch.repo
parent
33c15933
Changes
2
Hide whitespace changes
Inline
Side-by-side
rainboard/migrations/0013_branch_repo.py
0 → 100644
View file @
0b60d576
# Generated by Django 2.0.1 on 2018-02-05 13:52
from
django.db
import
migrations
,
models
import
django.db.models.deletion
def
populate_branch_repo
(
apps
,
schema_editor
):
Branch
=
apps
.
get_model
(
'rainboard'
,
'Branch'
)
Repo
=
apps
.
get_model
(
'rainboard'
,
'Repo'
)
for
branch
in
Branch
.
objects
.
all
():
if
branch
.
name
in
[
'master'
,
'devel'
]:
forge
=
branch
.
project
.
main_forge
.
slug
namespace
=
branch
.
project
.
main_namespace
.
slug
else
:
forge
,
namespace
=
branch
.
name
.
split
(
'/'
)[:
2
]
branch
.
repo
=
Repo
.
objects
.
get
(
forge__slug
=
forge
,
namespace__slug
=
namespace
,
project
=
branch
.
project
)
branch
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'rainboard'
,
'0012_branch_updated'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'branch'
,
name
=
'repo'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'rainboard.Repo'
),
),
migrations
.
RunPython
(
populate_branch_repo
),
migrations
.
AlterField
(
model_name
=
'branch'
,
name
=
'repo'
,
field
=
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'rainboard.Repo'
),
),
]
rainboard/models.py
View file @
0b60d576
...
...
@@ -344,6 +344,7 @@ class Branch(TimeStampedModel):
ahead
=
models
.
PositiveSmallIntegerField
(
blank
=
True
,
null
=
True
)
behind
=
models
.
PositiveSmallIntegerField
(
blank
=
True
,
null
=
True
)
updated
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
repo
=
models
.
ForeignKey
(
Repo
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
name
...
...
@@ -359,15 +360,10 @@ class Branch(TimeStampedModel):
commits
=
self
.
project
.
git
().
git
.
rev_list
(
f
'
{
self
}
..
{
branch
}
'
)
return
len
(
commits
.
split
(
'
\n
'
))
if
commits
else
0
def
remote
(
self
):
# TODO: ForeignKey to Repo
forge
,
namespace
,
branch
=
self
.
name
.
split
(
'/'
,
maxsplit
=
2
)
return
Repo
.
objects
.
get
(
forge__slug
=
forge
,
namespace__slug
=
namespace
,
project
=
self
.
project
).
git
()
def
git
(
self
):
git_repo
=
self
.
project
.
git
()
if
self
.
name
not
in
git_repo
.
branches
:
remote
=
self
.
re
mote
()
remote
=
self
.
re
po
.
git
()
_
,
_
,
branch
=
self
.
name
.
split
(
'/'
,
maxsplit
=
2
)
git_repo
.
create_head
(
self
.
name
,
remote
.
refs
[
branch
]).
set_tracking_branch
(
remote
.
refs
[
branch
])
return
git_repo
.
branches
[
self
.
name
]
...
...
@@ -376,7 +372,7 @@ class Branch(TimeStampedModel):
if
pull
:
self
.
project
.
main_repo
().
git
().
fetch
()
if
self
.
name
not
in
MAIN_BRANCHES
:
self
.
re
mote
().
fetch
()
self
.
re
po
.
git
().
fetch
()
main_branch
=
self
.
project
.
main_branch
()
self
.
ahead
=
self
.
get_ahead
(
main_branch
)
self
.
behind
=
self
.
get_behind
(
main_branch
)
...
...
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