From f5330dc00af537703a806669092fabe7d7fd7769 Mon Sep 17 00:00:00 2001 From: Uta Christoph Date: Tue, 16 Aug 2022 17:43:51 +0200 Subject: [PATCH 1/5] rename openMR --- .gitlab-ci.yml | 2 +- deployment-scripts/{openMr.ps1 => open-mr.ps1} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename deployment-scripts/{openMr.ps1 => open-mr.ps1} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c451e61..9de7c60 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ openMr: stage: openMr except: [master, dev, /^integration/.*$/] script: - - '&".\deployment-scripts\openMr.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' + - '&".\deployment-scripts\open-mr.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' cleanUpAndCreateBranches: stage: cleanUpAndCreateBranches diff --git a/deployment-scripts/openMr.ps1 b/deployment-scripts/open-mr.ps1 similarity index 100% rename from deployment-scripts/openMr.ps1 rename to deployment-scripts/open-mr.ps1 -- GitLab From 0f2727bcce6ca2e5aa928324829feb6eb879d769 Mon Sep 17 00:00:00 2001 From: Uta Christoph Date: Tue, 16 Aug 2022 17:45:35 +0200 Subject: [PATCH 2/5] rename cleanUpAndCreateBranches --- .gitlab-ci.yml | 6 +++--- ...ndCreateBranches.ps1 => cleanup-and-create-branches.ps1} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename deployment-scripts/{cleanUpAndCreateBranches.ps1 => cleanup-and-create-branches.ps1} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9de7c60..bd4c42a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ stages: - build - openMr - deploy - - cleanUpAndCreateBranches + - cleanupAndCreateBranches build: stage: build @@ -23,11 +23,11 @@ openMr: script: - '&".\deployment-scripts\open-mr.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' -cleanUpAndCreateBranches: +cleanupAndCreateBranches: stage: cleanUpAndCreateBranches only: [dev] script: - - '&".\deployment-scripts\cleanUpAndCreateBranches.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' + - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' when: manual build_integration: diff --git a/deployment-scripts/cleanUpAndCreateBranches.ps1 b/deployment-scripts/cleanup-and-create-branches.ps1 similarity index 100% rename from deployment-scripts/cleanUpAndCreateBranches.ps1 rename to deployment-scripts/cleanup-and-create-branches.ps1 -- GitLab From bb6a5a48f3e5f72105c780b1288d6a00e631d6f8 Mon Sep 17 00:00:00 2001 From: Uta Christoph Date: Tue, 16 Aug 2022 17:47:48 +0200 Subject: [PATCH 3/5] use predefined gitlab api v4 variable --- .gitlab-ci.yml | 4 ++-- deployment-scripts/cleanup-and-create-branches.ps1 | 6 +++--- deployment-scripts/open-mr.ps1 | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd4c42a..5622862 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,13 +21,13 @@ openMr: stage: openMr except: [master, dev, /^integration/.*$/] script: - - '&".\deployment-scripts\open-mr.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' + - '&".\deployment-scripts\open-mr.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' cleanupAndCreateBranches: stage: cleanUpAndCreateBranches only: [dev] script: - - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' + - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' when: manual build_integration: diff --git a/deployment-scripts/cleanup-and-create-branches.ps1 b/deployment-scripts/cleanup-and-create-branches.ps1 index b05e330..ca02c48 100644 --- a/deployment-scripts/cleanup-and-create-branches.ps1 +++ b/deployment-scripts/cleanup-and-create-branches.ps1 @@ -5,7 +5,7 @@ param( [string] $token ) -$queriedIntegrationBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/repository/branches?search=^integration") +$queriedIntegrationBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "/projects/" + $project + "/repository/branches?search=^integration") $queriedIntegrationBranch = $queriedIntegrationBranches | Sort name -desc | Select -First 1 $integrationBranchName = $queriedIntegrationBranch.Name @@ -17,8 +17,8 @@ if($currentBranchNumber -match "^\d+$") { $currentBranchNumber = $currentBranchNumber -as [int] $currentBranchNumber++ - $answer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Post -Uri ($api + "projects/" + $project + "/repository/branches?branch=integration/sprint-" + $splittedBranchName[$splittedBranchName.Length-2] + "-" + $currentBranchNumber + "&ref=dev") + $answer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Post -Uri ($api + "/projects/" + $project + "/repository/branches?branch=integration/sprint-" + $splittedBranchName[$splittedBranchName.Length-2] + "-" + $currentBranchNumber + "&ref=dev") Write $answer } -$deleteAnswer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Delete -Uri ($api + "projects/" + $project + "/repository/merged_branches") +$deleteAnswer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Delete -Uri ($api + "/projects/" + $project + "/repository/merged_branches") Write $deleteAnswer diff --git a/deployment-scripts/open-mr.ps1 b/deployment-scripts/open-mr.ps1 index 504d62c..9eed238 100644 --- a/deployment-scripts/open-mr.ps1 +++ b/deployment-scripts/open-mr.ps1 @@ -8,7 +8,7 @@ param( ) # check if mr target branch already exists -$queriedTargetBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/repository/branches?search=$queryTargetBranch") +$queriedTargetBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "/projects/" + $project + "/repository/branches?search=$queryTargetBranch") $queriedTargetBranch = $queriedTargetBranches | Sort name -desc | Select -First 1 if ($queriedTargetBranch -eq $null) { @@ -18,7 +18,7 @@ if ($queriedTargetBranch -eq $null) { $queriedTargetBranchName = $queriedTargetBranch.Name # check if mr already exists -$openedMRs = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/merge_requests?state=opened") +$openedMRs = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "/projects/" + $project + "/merge_requests?state=opened") $openedMR = $openedMRs | Where source_branch -eq $branch | Select -First 1 if ($openedMR -eq $null) { @@ -32,7 +32,7 @@ if ($openedMR -eq $null) { } # create mr - $createResponse = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -ContentType "application/json" -Method Post -Uri ($api + "projects/" + $project + "/merge_requests") -Body (ConvertTo-Json $body) + $createResponse = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -ContentType "application/json" -Method Post -Uri ($api + "/projects/" + $project + "/merge_requests") -Body (ConvertTo-Json $body) echo "Opened a new merge request: 'Draft: $branch' and assigned to you"; exit } -- GitLab From 82046f094342c4673eae64b85b4b4f591fe4cc3b Mon Sep 17 00:00:00 2001 From: Uta Christoph Date: Tue, 16 Aug 2022 17:50:12 +0200 Subject: [PATCH 4/5] use groupApiToken --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5622862..a1455a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,13 +21,13 @@ openMr: stage: openMr except: [master, dev, /^integration/.*$/] script: - - '&".\deployment-scripts\open-mr.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' + - '&".\deployment-scripts\open-mr.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${groupApiToken} -queryTargetBranch "^integration"' cleanupAndCreateBranches: stage: cleanUpAndCreateBranches only: [dev] script: - - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' + - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${groupApiToken}' when: manual build_integration: -- GitLab From d897cbc2b682980f02e918cfe291895eb56b71c8 Mon Sep 17 00:00:00 2001 From: Uta Christoph Date: Tue, 16 Aug 2022 17:55:10 +0200 Subject: [PATCH 5/5] correct yml stage --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a1455a3..8718a0b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,7 +24,7 @@ openMr: - '&".\deployment-scripts\open-mr.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${groupApiToken} -queryTargetBranch "^integration"' cleanupAndCreateBranches: - stage: cleanUpAndCreateBranches + stage: cleanupAndCreateBranches only: [dev] script: - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${groupApiToken}' -- GitLab