From f4311a3a03a4c06b4f7aca68fa98e14855f1ed83 Mon Sep 17 00:00:00 2001
From: Lorenzo Pagliai <lorenzo.pagliai@seco.com>
Date: Fri, 10 Feb 2023 09:13:34 +0100
Subject: [PATCH] [MIGRATION] Change group name and master branch

* Change all occurrencies of 'yocto_ng' with 'edgehog' due to group
 rename
* Change all occurrencies of 'kirkstone/develop' with 'kirkstone' due
to master branch rename
* Update documentation references accordingly
* Changelog script loops over MR opened both to 'kirkstone/develop' and
'kirkstone' branch
* Minor fix in notify job
---
 .gitlab-ci.yml                            | 10 +++++-----
 README.md                                 |  8 ++++----
 docs/automatic-manifest-integration.md    |  8 ++++----
 docs/gitlab-ci-deployment.md              |  2 +-
 docs/manifest-pipeline.md                 |  6 +++---
 layers-integration.yml                    |  4 ++--
 manifest-integration-pipelines.yml.jinja2 |  2 +-
 manifest-integration.yml                  |  6 +++---
 manifest-pipeline-yocto.yml               |  8 ++++----
 old/manifest-integration_seco_ne.yml      |  2 +-
 scripts/changelog_generator.py            | 12 +++++++++++-
 11 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7a713df..f8290db 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -143,7 +143,7 @@ executable:
 integrate-yocto:kirkstone:
   extends: .integrate-yocto
   variables:
-    MANIFEST_BRANCH: kirkstone/develop
+    MANIFEST_BRANCH: kirkstone
 
 
 # --------------------------------------------------------------------------------------
@@ -161,14 +161,14 @@ integrate-yocto:kirkstone:
 .build-ci-test:
   extends: .build
   trigger:
-    project: yocto_ng/infrastructure/ci-test/minimal-manifest
+    project: edgehog/infrastructure/ci-test/minimal-manifest
     branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${MANIFEST_BRANCH}"
     strategy: depend
 
 .build-yocto:
   extends: .build
   trigger:
-    project: yocto_ng/seco-manifest
+    project: edgehog/seco-manifest
     branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${MANIFEST_BRANCH}"
     strategy: depend
 
@@ -196,7 +196,7 @@ build-yocto:kirkstone:
   extends: .build-yocto
   needs: ["integrate-yocto:kirkstone"]
   variables:
-    MANIFEST_BRANCH: kirkstone/develop
+    MANIFEST_BRANCH: kirkstone
 
 
 # --------------------------------------------------------------------------------------
@@ -223,4 +223,4 @@ merge-yocto:
     - .integrate-yocto
     - .merge
   variables:
-    MANIFEST_BRANCH: kirkstone/develop
+    MANIFEST_BRANCH: kirkstone
diff --git a/README.md b/README.md
index a6378d6..06f4b0c 100644
--- a/README.md
+++ b/README.md
@@ -17,16 +17,16 @@ Most scripts inside this repository need a [group GitLab access token][2] of
 a user with access to all relevant repositories (manifest and all contained
 projects) in order to work correctly.
 We have created the **EdgeBot** group access token for this task. The token has
-maintainer permissions in the [`yocto_ng` group][3] and has all of the token 
+maintainer permissions in the [`edgehog` group][3] and has all of the token 
 permissions enabled (read/write API access, read/write registry access, etc.).
 
 The group access token value is provided via the CI environment variable
-`GITBOT_TOKEN` for all projects in the `yocto_ng` group (set in the
+`GITBOT_TOKEN` for all projects in the `edgehog` group (set in the
 [group's CI/CD settings][4] under "Variables").
 
 [2]: https://docs.gitlab.com/ee/user/group/settings/group_access_tokens.html
-[3]: https://git.seco.com/yocto_ng
-[4]: https://git.seco.com/groups/yocto_ng/-/settings/ci_cd
+[3]: https://git.seco.com/edgehog
+[4]: https://git.seco.com/groups/edgehog/-/settings/ci_cd
 
 
 <!----------------------------------------------------------------------------->
diff --git a/docs/automatic-manifest-integration.md b/docs/automatic-manifest-integration.md
index b7e7fcf..1dee3fd 100644
--- a/docs/automatic-manifest-integration.md
+++ b/docs/automatic-manifest-integration.md
@@ -68,8 +68,8 @@ SRCREV_pn-xconfig = "0fc1ea45b55e729d551bb7d40dd25fbde02ee1b6"
 Each project is listed with its bitbake **recipe name** after `SRCREV_PN-` and
 the fixed git **revision**.
 
-[1]: https://git.seco.com/yocto_ng/seco-manifest
-[2]: https://git.seco.com/yocto_ng/seco-manifest/-/blob/kirkstone/develop/distro/seco-distro.xml
+[1]: https://git.seco.com/edgehog/seco-manifest
+[2]: https://git.seco.com/edgehog/seco-manifest/-/blob/kirkstone/distro/seco-distro.xml
 [3]: https://gerrit.googlesource.com/git-repo
 
 
@@ -187,7 +187,7 @@ the git revision in the `SRCREV.conf` file on project changes.
    `git submodule add ../../../infrastructure/gitlab-ci .gitlab-ci`
 
 2. Add an approriate `.gitlab-ci.yml` file. For example, copy it from the
-   repository [meta-seco-edgehog][8]. Modify the following variables in the file:
+   repository [meta-seco-edgehog-things][8]. Modify the following variables in the file:
    * `BB_RECIPE_NAME`: Set the name of the bitbake recipe
 
 3. Create a corresponding entry in the `SRCREV.conf` file of the manifest repo:\
@@ -207,4 +207,4 @@ the git revision in the `SRCREV.conf` file on project changes.
 3. Check that the default branch is protected and that *Maintainers + 
    Developers* are allowed to merge (Repository -> Protected branches)
 
-[8]: https://git.seco.com/yocto_ng/layers/seco/meta-seco-edgehog
+[8]: https://git.seco.com/edgehog/layers/seco/meta-seco-edgehog-things
diff --git a/docs/gitlab-ci-deployment.md b/docs/gitlab-ci-deployment.md
index 6a4e2bf..9b12a46 100644
--- a/docs/gitlab-ci-deployment.md
+++ b/docs/gitlab-ci-deployment.md
@@ -17,7 +17,7 @@ As this repo contains all the CI code, some extra care is needed in order not to
 break the whole thing. To allow testing the CI before everything is merged into the Yocto pipeline, a sandbox environment in the form of a set of test projects is
 available in the [ci-test group][1].
 
-[1]: https://git.seco.com/yocto_ng/infrastructure/ci-test
+[1]: https://git.seco.com/edgehog/infrastructure/ci-test
 
 
 <!----------------------------------------------------------------------------->
diff --git a/docs/manifest-pipeline.md b/docs/manifest-pipeline.md
index 7a81d80..47a7f4a 100644
--- a/docs/manifest-pipeline.md
+++ b/docs/manifest-pipeline.md
@@ -7,7 +7,7 @@ work, like building images, generating docs and deploying image to download
 servers and triggering tests in LAVA (TO DO). The pipeline running in the manifest
 repository is described in the `manifest-pipeline-yocto.yml` [file][1].
 
-[1]:https://git.seco.com/yocto_ng/infrastructure/gitlab-ci/-/blob/master/manifest-pipeline-yocto.yml
+[1]:https://git.seco.com/edgehog/infrastructure/gitlab-ci/-/blob/master/manifest-pipeline-yocto.yml
 
 <!----------------------------------------------------------------------------->
 ## Triggers
@@ -34,7 +34,7 @@ one it will then be necessary to include at the beginning of the
 
 The build jobs either compile the Egdehog image and the bundle.
 
-[2]:https://git.seco.com/yocto_ng/infrastructure/gitlab-ci/-/tree/master/boards
+[2]:https://git.seco.com/edgehog/infrastructure/gitlab-ci/-/tree/master/boards
 
 <!----------------------------------------------------------------------------->
 ## Deploy and upload jobs
@@ -50,7 +50,7 @@ defined at group level][3]:
 * `AZURE_CONTAINER_NAME`: the name of the blob storage container used to store software artifacts.
 * `AZURE_STORAGE_SAS_TOKEN`: the [SAS token][4] associated to the corresponding Azure container.
 
-[3]:https://git.seco.com/groups/yocto_ng/-/settings/ci_cd
+[3]:https://git.seco.com/groups/edgehog/-/settings/ci_cd
 [4]:https://learn.microsoft.com/it-it/azure/cognitive-services/translator/document-translation/create-sas-tokens?tabs=Containers
 
 <!----------------------------------------------------------------------------->
diff --git a/layers-integration.yml b/layers-integration.yml
index ca522a0..4c137f7 100644
--- a/layers-integration.yml
+++ b/layers-integration.yml
@@ -23,8 +23,8 @@ variables:
   # FIXME: This is only necessary due to the following GitLab limitation:
   # https://gitlab.com/gitlab-org/gitlab/-/issues/209904
   # As soon as this gets fixed upstream, the hard-coded branch name should be removed.
-  MANIFEST_PROJECT: yocto_ng/seco-manifest
-  MASTER_BRANCH_LAYER: kirkstone/develop
+  MANIFEST_PROJECT: edgehog/seco-manifest
+  MASTER_BRANCH_LAYER: kirkstone
   BB_RECIPE_NAME: none
   SRCREV_FILE: conf/SRCREV.conf
 
diff --git a/manifest-integration-pipelines.yml.jinja2 b/manifest-integration-pipelines.yml.jinja2
index 01d71a8..6c21306 100644
--- a/manifest-integration-pipelines.yml.jinja2
+++ b/manifest-integration-pipelines.yml.jinja2
@@ -3,7 +3,7 @@
 # Global
 # --------------------------------------------------------------------------------------
 include:
-  - project: edgehog/yocto_ng/gitlab-ci
+  - project: edgehog/infrastructure/gitlab-ci
     ref: {{ GITLAB_CI_REVISION }}
     file: common.yml
 
diff --git a/manifest-integration.yml b/manifest-integration.yml
index 70f3c46..31df50b 100644
--- a/manifest-integration.yml
+++ b/manifest-integration.yml
@@ -24,8 +24,8 @@ variables:
   # https://gitlab.com/gitlab-org/gitlab/-/issues/209904
   # As soon as this gets fixed upstream, the hard-coded branch name should be removed.
   MANIFEST_PROJECT: seco-manifest
-  MANIFEST_GROUP: yocto_ng
-  MASTER_BRANCH_MANIFEST: kirkstone/develop
+  MANIFEST_GROUP: edgehog
+  MASTER_BRANCH_MANIFEST: kirkstone
   BB_RECIPE_NAME: none
 
   DEPLOYPATH_TEST: "/artifacts/${CI_JOB_ID}/"
@@ -131,7 +131,7 @@ build:
   #script:
   #  - echo "Building"
   trigger:
-    project: yocto_ng/seco-manifest
+    project: edgehog/seco-manifest
     branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${MASTER_BRANCH_MANIFEST}"
     strategy: depend
 # 
diff --git a/manifest-pipeline-yocto.yml b/manifest-pipeline-yocto.yml
index c181989..6d43417 100644
--- a/manifest-pipeline-yocto.yml
+++ b/manifest-pipeline-yocto.yml
@@ -15,12 +15,12 @@ variables:
   # The id of the gitlab project used in the rules section to not run pipelines in
   # forked projects. Using variable here, to allow override in other projects including
   # this file.
-  MANIFEST_PROJECT_ID: 2307
+  MANIFEST_PROJECT_ID: 1456
 
   # In the manifest, the remotes are specified by an identifier. This is used to find
   # out included projects for the retrigger job. In custom manifests, the remote may be
   # named differently, so we need a variable that may be overriden.
-  CI_PARAM_SECO_REMOTE: yocto_ng
+  CI_PARAM_SECO_REMOTE: edgehog
 
   # GitLab group to search for projects to retrigger
   RETRIGGER_GROUP: ${CI_PROJECT_ROOT_NAMESPACE}
@@ -591,7 +591,7 @@ notify:
        link_report="$(echo $link_report | sed -E 's/\s.*$//')"
        jq --arg link_var $link_report '.potentialAction[1].targets[0].uri = $link_var' notification_1.json > notification_2.json
 
-       changelog_report="$(az storage blob url --container-name $AZURE_CONTAINER_NAME --name Build_reports/Changelog_edgehog_${tag}.txt)"
+       changelog_report="$(az storage blob url --container-name $AZURE_CONTAINER_NAME --name Build_reports/Changelog_edgehog_${tag}.md)"
        changelog_report="$(echo $changelog_report | sed -E 's/\s.*$//')"
        jq --arg changelog_var $changelog_report '.potentialAction[2].targets[0].uri = $changelog_var' notification_2.json > notification_3.json
        sed -i -E 's/\\"//g' notification_3.json
@@ -601,7 +601,7 @@ notify:
 
        curl -X POST -H "Content-Type: application/json" --data @notification_4.json $WEBHOOK
 
-       echo "${changelog_report#?}" > changelog_link.txt
+       echo "${changelog_report#?}" | sed 's/\\.*//' > changelog_link.txt
   
   artifacts:
     expire_in: 4 weeks
diff --git a/old/manifest-integration_seco_ne.yml b/old/manifest-integration_seco_ne.yml
index 9c6204f..0c17db3 100644
--- a/old/manifest-integration_seco_ne.yml
+++ b/old/manifest-integration_seco_ne.yml
@@ -18,7 +18,7 @@ variables:
   # The BB_RECIPE_NAME is passed to the python scripts below anyway, but not
   # used for projects referenced in the manifest file.
   MANIFEST_PROJECT: seco-manifest
-  MASTER_BRANCH_MANIFEST: kirkstone/develop
+  MASTER_BRANCH_MANIFEST: kirkstone
   MASTER_BRANCH_PROJECT: main
   BB_RECIPE_NAME: none
 
diff --git a/scripts/changelog_generator.py b/scripts/changelog_generator.py
index 52538cf..39edfc9 100755
--- a/scripts/changelog_generator.py
+++ b/scripts/changelog_generator.py
@@ -35,7 +35,7 @@ RK_PROJECT_ID = "1458"
 INTEL_PROJECT_ID = "2109"
 MANIFEST_PROJECT_ID = "1456"
 
-DEFAULTBRANCH = "kirkstone/develop"
+DEFAULTBRANCH = "kirkstone"
 
 GITLAB_TIMEFORMAT = "%Y-%m-%dT%H:%M:%S.%f%z"
 TIMEFORMAT = "%Y-%m-%d %H:%M"
@@ -282,6 +282,16 @@ def main(args):
                 if r.add_mergerequest(m):
                     break
 
+        #Iterate again over MR because of the kirkstone/develop -> kirkstone changement
+        old_branch="kirkstone/develop"
+        for mr in p.project.mergerequests.list(
+            scope="all", state="merged", target_branch=old_branch, per_page="10000"
+        ):
+            m = MergeRequest(mr, p)
+            for r in releases:
+                if r.add_mergerequest(m):
+                    break
+
     # Sort by date, newest first
     releases = sorted(releases, key=lambda d: d.tag.timestamp, reverse=True)
 
-- 
GitLab