diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-09-07 09:58:15 +0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-12-05 12:54:10 -0200 |
commit | fe673b492769dc888268a1b2ac25342faa18a817 (patch) | |
tree | 11c2e4b9126feb999b21c54bdd8343b59bab2172 /app/workers/update_head_pipeline_for_merge_request_worker.rb | |
parent | 003a816afa885d56aa1eb4aadbad2b13b1baa25b (diff) | |
download | gitlab-ce-fe673b492769dc888268a1b2ac25342faa18a817.tar.gz |
Ensure pippeline corresponds with the sha of an MR
Diffstat (limited to 'app/workers/update_head_pipeline_for_merge_request_worker.rb')
-rw-r--r-- | app/workers/update_head_pipeline_for_merge_request_worker.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/workers/update_head_pipeline_for_merge_request_worker.rb b/app/workers/update_head_pipeline_for_merge_request_worker.rb new file mode 100644 index 00000000000..ebe2435bbe5 --- /dev/null +++ b/app/workers/update_head_pipeline_for_merge_request_worker.rb @@ -0,0 +1,15 @@ +class UpdateHeadPipelineForMergeRequestWorker + include Sidekiq::Worker + + sidekiq_options queue: 'pipeline_default' + + def perform(merge_request_id) + merge_request = MergeRequest.find(merge_request_id) + pipeline = Ci::Pipeline.where(project: merge_request.source_project, ref: merge_request.source_branch).last + + return unless pipeline && pipeline.latest? + raise ArgumentError, 'merge request sha does not equal pipeline sha' if merge_request.diff_head_sha != pipeline.sha + + merge_request.update_attribute(:head_pipeline_id, pipeline.id) + end +end |