summaryrefslogtreecommitdiff
path: root/app/models/project_status.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-05 15:13:34 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-05 15:13:34 +0200
commitf17c4950fa5a951102d5592dc962f20e302b44aa (patch)
tree9c6f7078d1db168d8154739d52fc062d5987c3c4 /app/models/project_status.rb
parent056df41ed16f6eddf3271caad93a118f97e8b58c (diff)
downloadgitlab-ci-f17c4950fa5a951102d5592dc962f20e302b44aa.tar.gz
Refactor commits/builds logic
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/project_status.rb')
-rw-r--r--app/models/project_status.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/models/project_status.rb b/app/models/project_status.rb
new file mode 100644
index 0000000..b14cb4f
--- /dev/null
+++ b/app/models/project_status.rb
@@ -0,0 +1,45 @@
+module ProjectStatus
+ def status
+ last_commit.status if last_commit
+ end
+
+ def broken?
+ last_commit.failed? if last_commit
+ end
+
+ def success?
+ last_commit.success? if last_commit
+ end
+
+ def broken_or_success?
+ broken? || success?
+ end
+
+ def last_commit
+ @last_commit ||= commits.last if commits.any?
+ end
+
+ def last_commit_date
+ last_commit.try(:created_at)
+ end
+
+ def human_status
+ status
+ end
+
+ # only check for toggling build status within same ref.
+ def last_commit_changed_status?
+ ref = last_commit.ref
+ last_commits = commits.where(ref: ref).order('id DESC').limit(2)
+
+ if last_commits.size < 2
+ false
+ else
+ last_commits[0].status != last_commits[1].status
+ end
+ end
+
+ def last_commit_for_ref(ref)
+ commits.where(ref: ref).order('id DESC').first
+ end
+end