Skip to content
Snippets Groups Projects
Commit 1ba150e1 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Add committed_at to commits to properly order last commit (the force push issue)

parent 1fdd1fa6
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -11,6 +11,7 @@ v7.14.0 (unreleased)
- Allow to define variables from YAML
- Added support for CI skipped status
- Fix broken yaml error saving
- Add committed_at to commits to properly order last commit (the force push issue)
- Rename type(s) to stage(s)
- Add missing stage when doing retry
- Require variable keys to be not-empty and unique
Loading
Loading
Loading
Loading
@@ -40,9 +40,9 @@ class ProjectsController < ApplicationController
def show
@ref = params[:ref]
 
@commits = @project.commits
@commits = @project.commits.reverse_order
@commits = @commits.where(ref: @ref) if @ref
@commits = @commits.order('id DESC').page(params[:page]).per(20)
@commits = @commits.page(params[:page]).per(20)
end
 
def integration
Loading
Loading
Loading
Loading
@@ -245,6 +245,10 @@ class Commit < ActiveRecord::Base
commits.present? && commits.last[:message] =~ /(\[ci skip\])/
end
 
def update_committed!
update!(committed_at: DateTime.now)
end
private
 
def save_yaml_error(error)
Loading
Loading
Loading
Loading
@@ -28,7 +28,7 @@
class Project < ActiveRecord::Base
include ProjectStatus
 
has_many :commits, dependent: :destroy
has_many :commits, ->() { order(:committed_at) }, dependent: :destroy
has_many :builds, through: :commits, dependent: :destroy
has_many :runner_projects, dependent: :destroy
has_many :runners, through: :runner_projects
Loading
Loading
@@ -110,9 +110,9 @@ ls -la
end
 
def ordered_by_last_commit_date
last_commit_subquery = "(SELECT project_id, MAX(created_at) created_at FROM commits GROUP BY project_id)"
last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM commits GROUP BY project_id)"
joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON projects.id = last_commit.project_id").
order("CASE WHEN last_commit.created_at IS NULL THEN 1 ELSE 0 END, last_commit.created_at DESC")
order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC")
end
 
def search(query)
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@ module ProjectStatus
# 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)
last_commits = commits.where(ref: ref).last(2)
 
if last_commits.size < 2
false
Loading
Loading
@@ -40,6 +40,6 @@ module ProjectStatus
end
 
def last_commit_for_ref(ref)
commits.where(ref: ref).order('id DESC').first
commits.where(ref: ref).last
end
end
Loading
Loading
@@ -40,6 +40,7 @@ class CreateCommitService
commit = project.commits.create(data)
end
 
commit.update_committed!
commit.create_builds unless commit.builds.any?
 
commit
Loading
Loading
class AddCommittedAtToCommits < ActiveRecord::Migration
def up
add_column :commits, :committed_at, :timestamp
add_index :commits, [:project_id, :committed_at]
end
end
class UpdateCommittedAtWithCreatedAt < ActiveRecord::Migration
def up
execute('UPDATE commits SET committed_at=created_at WHERE committed_at IS NULL')
end
end
Loading
Loading
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
 
ActiveRecord::Schema.define(version: 20150803142346) do
ActiveRecord::Schema.define(version: 20150806091655) do
 
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Loading
Loading
@@ -58,8 +58,10 @@ ActiveRecord::Schema.define(version: 20150803142346) do
t.datetime "updated_at"
t.boolean "tag", default: false
t.text "yaml_errors"
t.datetime "committed_at"
end
 
add_index "commits", ["project_id", "committed_at"], name: "index_commits_on_project_id_and_committed_at", using: :btree
add_index "commits", ["project_id", "sha"], name: "index_commits_on_project_id_and_sha", using: :btree
add_index "commits", ["project_id"], name: "index_commits_on_project_id", using: :btree
add_index "commits", ["sha"], name: "index_commits_on_sha", using: :btree
Loading
Loading
Loading
Loading
@@ -54,8 +54,8 @@ describe Project do
oldest_project = FactoryGirl.create :project
project_without_commits = FactoryGirl.create :project
 
FactoryGirl.create :commit, created_at: 1.hour.ago, project: newest_project
FactoryGirl.create :commit, created_at: 2.hour.ago, project: oldest_project
FactoryGirl.create :commit, committed_at: 1.hour.ago, project: newest_project
FactoryGirl.create :commit, committed_at: 2.hour.ago, project: oldest_project
 
Project.ordered_by_last_commit_date.should == [newest_project, oldest_project, project_without_commits]
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment