From b2fdee5ac1e9c7b79b9a444b922976d506c209f9 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Mon, 22 Mar 2021 15:17:15 +0100
Subject: [PATCH] Fix code owner functionality

There was a problem with the script such that in some cases to many code
owners were informed. When in between the creation of the MR and the
runtime of the script the master branch of the official repository was
updated the code owners of the MR changes as well as the code owners of
the updated code from the official repository wer informed.
To avoid sending information for code which is already implemented in the
official repository the local working copy is rebased before extracting the
changed files.

Fix user name of Sergey Gorbunov in CODEOWNERS file. Sergey has two GitLab
accounts and the wrong was chosen.
---
 CODEOWNERS                   | 8 ++++----
 scripts/inform_codeowners.sh | 4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/CODEOWNERS b/CODEOWNERS
index 49d223de30..30a501394e 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -12,11 +12,11 @@
 
 /macro/C2F/      @i.selyuzhenkov
 /macro/analysis/ @i.selyuzhenkov
-/macro/KF/       @s.gorbunov @v.akishina
+/macro/KF/       @se.gorbunov @v.akishina
 
 # Core
 /core/             @f.uhlig @v.friese @p.-a.loizeau
-/core/qa/          @s.gorbunov
+/core/qa/          @se.gorbunov
 /core/data/test/   @f.uhlig
 /core/data/raw/    @p.-a.loizeau
 /core/base/utils/  @f.uhlig @s.lebedev
@@ -30,9 +30,9 @@
 # Reco
 /reco/              @f.uhlig @v.friese @p.-a.loizeau
 /reco/littrack/     @s.lebedev @andrey.lebedev
-/reco/L1/           @s.gorbunov @v.akishina
+/reco/L1/           @se.gorbunov @v.akishina
 /reco/eventbuilder/ @d.smith
-/reco/KF/           @s.gorbunov @v.akishina
+/reco/KF/           @se.gorbunov @v.akishina
 
 # Analysis
 /analysis/                                 @i.selyuzhenkov
diff --git a/scripts/inform_codeowners.sh b/scripts/inform_codeowners.sh
index 4403dd252a..1ce3b9ad30 100755
--- a/scripts/inform_codeowners.sh
+++ b/scripts/inform_codeowners.sh
@@ -137,6 +137,10 @@ function generate_file_list() {
   fi
   echo "Upstream name is :" $UPSTREAM
 
+  # Rebase the MR to extract the changed files properly
+  # If upstream/master was changed while the pipline was running one would otherwise get
+  # a wrong list of files
+  git rebase $UPSTREAM/master
   BASE_COMMIT=$UPSTREAM/master
   CHANGED_FILES=$(git diff --name-only $BASE_COMMIT)
 }
-- 
GitLab