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
793f97ac
Commit
793f97ac
authored
Feb 27, 2018
by
Guilhem Saurel
Browse files
handling deleted branches
parent
4058cc34
Changes
2
Hide whitespace changes
Inline
Side-by-side
rainboard/migrations/0006_branch_deleted.py
0 → 100644
View file @
793f97ac
# Generated by Django 2.0.2 on 2018-02-27 13:39
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'rainboard'
,
'0005_contributor_agreement_signed'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'branch'
,
name
=
'deleted'
,
field
=
models
.
BooleanField
(
default
=
False
),
),
]
rainboard/models.py
View file @
793f97ac
...
...
@@ -410,14 +410,7 @@ class Repo(TimeStampedModel):
branch_name
=
f
'
{
self
.
forge
.
slug
}
/
{
self
.
namespace
.
slug
}
/
{
build
[
"branch"
][
"name"
]
}
'
branch
,
created
=
Branch
.
objects
.
get_or_create
(
name
=
branch_name
,
project
=
self
.
project
,
repo
=
self
)
if
created
:
try
:
branch
.
update
()
except
git
.
exc
.
GitCommandError
:
# Some guys might delete some branches…
# eg. https://travis-ci.org/stack-of-tasks/dynamic-graph/builds/246184885
logger
.
error
(
f
' DELETED BRANCH for
{
self
.
project
}
:
{
branch_name
}
'
)
branch
.
delete
()
continue
branch
.
update
()
started
=
build
[
'started_at'
]
if
build
[
'started_at'
]
is
not
None
else
build
[
'finished_at'
]
CIBuild
.
objects
.
get_or_create
(
repo
=
self
,
build_id
=
build
[
'id'
],
defaults
=
{
'passed'
:
TRAVIS_STATE
[
build
[
'state'
]],
...
...
@@ -447,6 +440,7 @@ class Branch(TimeStampedModel):
behind
=
models
.
PositiveSmallIntegerField
(
blank
=
True
,
null
=
True
)
updated
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
repo
=
models
.
ForeignKey
(
Repo
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
deleted
=
models
.
BooleanField
(
default
=
False
)
def
__str__
(
self
):
return
self
.
name
...
...
@@ -471,15 +465,20 @@ class Branch(TimeStampedModel):
return
git_repo
.
branches
[
self
.
name
]
def
update
(
self
,
pull
=
True
):
if
pull
:
self
.
repo
.
fetch
()
if
self
.
repo
!=
self
.
project
.
main_repo
():
self
.
project
.
main_repo
().
fetch
()
main_branch
=
self
.
project
.
main_branch
()
if
main_branch
is
not
None
:
self
.
ahead
=
self
.
get_ahead
(
main_branch
)
self
.
behind
=
self
.
get_behind
(
main_branch
)
self
.
updated
=
self
.
git
().
commit
.
authored_datetime
if
self
.
deleted
:
return
try
:
if
pull
:
self
.
repo
.
fetch
()
if
self
.
repo
!=
self
.
project
.
main_repo
():
self
.
project
.
main_repo
().
fetch
()
main_branch
=
self
.
project
.
main_branch
()
if
main_branch
is
not
None
:
self
.
ahead
=
self
.
get_ahead
(
main_branch
)
self
.
behind
=
self
.
get_behind
(
main_branch
)
self
.
updated
=
self
.
git
().
commit
.
authored_datetime
except
(
git
.
exc
.
GitCommandError
,
IndexError
):
self
.
deleted
=
True
self
.
save
()
def
ci
(
self
):
...
...
@@ -655,6 +654,9 @@ class Tag(models.Model):
ordering
=
(
'name'
,)
unique_together
=
(
'name'
,
'project'
)
def
__str__
(
self
):
return
f
'
{
self
.
project
}
{
self
.
name
}
'
class
Contributor
(
models
.
Model
):
projects
=
models
.
ManyToManyField
(
Project
)
...
...
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