Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2025-06-07 00:11:50 +00:00
parent 7a93bc87d7
commit 668bbbd1fb
3 changed files with 67 additions and 0 deletions

View File

@ -270,3 +270,15 @@ db:docs-up-to-date:
}
run_with_custom_exit_code db_docs_up_to_date
db:invalidate-old-pipeline-results:
extends:
- .db-job-base
- .db:rules:invalidate-old-pipeline-results
stage: post-test
needs: []
script:
- |
git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
export MOST_RECENT_COMMIT_TIMESTAMP="$(git log origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME --pretty=format:"%at" | head -n 1)"
bundle exec ruby scripts/database/mark_pipeline_comments.rb $CI_MERGE_REQUEST_IID $MOST_RECENT_COMMIT_TIMESTAMP

View File

@ -1025,6 +1025,12 @@
- <<: *if-merge-request
changes: *db-docs-patterns
.db:rules:invalidate-old-pipeline-results:
rules:
- <<: *if-merge-request
changes: *db-patterns
when: always
################
# Shared rules #
################

View File

@ -0,0 +1,49 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
require 'json'
require 'time'
require 'gitlab'
unless ENV['CI'] && ENV['CI_MERGE_REQUEST_ID']
puts 'Necessary environment variables CI and CI_MERGE_REQUEST_ID not defined.'
exit(-1)
end
ENDPOINT = ENV.fetch('CI_API_V4_URL')
PROJECT_PATH = ENV.fetch('CI_PROJECT_PATH')
TOKEN = ENV.fetch('DATABASE_PROJECT_TOKEN')
DB_PIPELINE_NOTE_TAG = 'gitlab-org/database-team/gitlab-com-database-testing:identifiable-note'
INVALIDATED_RESULTS_MSG_TAG = 'gitlab-org/database-team/gitlab-com-database-testing:identifiable-note-invalidated'
INVALIDATED_RESULTS_MSG = <<~MSG.freeze
## ⚠️
Please note that the database testing pipeline results in this comment
are no longer valid due to a commit being added to the merge request that has
changed one or more files.
Please run another database testing pipeline for the most accurate results.
<!-- #{INVALIDATED_RESULTS_MSG_TAG} -->
***
MSG
merge_request_id = ARGV[0]
most_recent_commit_timestamp = Time.at(ARGV[1].to_i)
client = Gitlab.client(endpoint: ENDPOINT, private_token: TOKEN)
puts "Fetching discussions on merge request #{merge_request_id}"
client.merge_request_notes(PROJECT_PATH, merge_request_id).auto_paginate.each do |discussion|
next unless discussion.body.include?(DB_PIPELINE_NOTE_TAG)
next if discussion.body.include? INVALIDATED_RESULTS_MSG_TAG
next unless Time.iso8601(discussion.created_at) < most_recent_commit_timestamp
annotated_body = "#{INVALIDATED_RESULTS_MSG}#{discussion.body}"
client.edit_merge_request_note(PROJECT_PATH, merge_request_id, discussion.id, annotated_body)
end