Merge branch '6-10-11-fix-bugs' into 'development'

fix: numerous bugs

See merge request nofusscomputing/projects/gitlab-ci!12
This commit is contained in:
2022-01-15 03:50:56 +00:00
3 changed files with 36 additions and 40 deletions

View File

@ -1,5 +1,6 @@
variables:
JOB_ROOT_DIR: '.'
GIT_SUBMODULE_STRATEGY: recursive
MY_PROJECT_ID: "28543717"
stages:

View File

@ -22,19 +22,13 @@
- pip install -r $ROOT_DIR/conventional_commits/requirements.txt
- echo "[DEBUG] CI_PROJECT_ID[$CI_PROJECT_ID]"
- echo "[DEBUG] CI_COMMIT_BRANCH[$CI_COMMIT_BRANCH]"
- $ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --branch $CI_COMMIT_BRANCH --target-branch
- target_branch=$($ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --branch $CI_COMMIT_BRANCH --target-branch)
- echo "[DEBUG] Target Branch[$target_branch]"
- git clone --depth 150 -b $target_branch $CI_REPOSITORY_URL check
- cd check
- git remote rm origin
- git remote add origin $CI_REPOSITORY_URL
- git fetch --all
- git checkout --track origin/$CI_COMMIT_BRANCH
- git submodule update --init
- git show-branch -a
- target_branch=$(git show-branch -a | awk 'BEGIN { FS="\n\s+*" } { print $1 }' | awk '{print $2}' | grep '\[' | sed 's/.*\[origin\/\(.*\)\].*/\1/' | grep -v '\[' | grep -v $(git rev-parse --abbrev-ref HEAD) | grep -vi 'HEAD' | awk 'BEGIN{ RS = "" ; FS = "\n" }{print $1}')
- echo "[DEBUG] Target Branch[$target_branch]"
- if [ -d "gitlab-ci" ]; then ls -la gitlab-ci; fi
- first_sha1=$(git log $target_branch..$CI_COMMIT_BRANCH --format=format:%H | tail -1)
- first_sha1=$(git log origin/$target_branch..$CI_COMMIT_BRANCH --format=format:%H | tail -1)
- echo "[DEBUG] First Commit SHA[$first_sha1]"
- echo "[DEBUG] artifacts directory [$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME]"
after_script:
@ -61,6 +55,7 @@ MR Title:
extends:
- .conventional_commit
script:
- echo "[DEBUG] Merge Request Title[$($ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --title --branch $CI_COMMIT_BRANCH)]"
- cz_exit=0 && cz check --message "$($ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --title --branch $CI_COMMIT_BRANCH)" > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/cz_output.log" 2>&1 || cz_exit=$?
- . $ROOT_DIR/conventional_commits/scripts/cz_junit.sh > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$CI_JOB_NAME-cz.junit.xml"

View File

@ -9,13 +9,11 @@ import getopt
import json
import requests
get_first_commit = False
get_mr_title = False
get_target_branch = False
project_id = ''
try:
opts, args = getopt.getopt(sys.argv[1:],"hic:t:ti:p:b:o",["commit","token=", "title", "project=", "branch=", "target-branch"])
opts, args = getopt.getopt(sys.argv[1:],"hi:t:ti:p:b",["token=", "title", "project=", "branch="])
except getopt.GetoptError:
print('test.py [-c | --commit] [-t | --token {token}]')
@ -27,9 +25,9 @@ for opt, arg in opts:
if opt == '-h':
print('[commit.py] -i <inputfile> -o <outputfile>')
sys.exit()
elif opt in ("-c", "--commit"):
get_first_commit = True
elif opt in ("-t", "--token"):
if arg is None:
raise ValueError('Token switch was specified, however no token was supplied.')
ci_job_token = arg
elif opt in ("-ti", "--title"):
get_mr_title = True
@ -37,29 +35,39 @@ for opt, arg in opts:
project_id = str(arg)
elif opt in ("-b", "--branch"):
git_branch = arg
elif opt in ("-o", "--target-branch"):
get_target_branch = True
# private token or personal token authentication
#gl = gitlab.Gitlab('https://gitlab.com', private_token=ci_job_token)
url = 'https://gitlab.com/api/v4/projects/' + project_id + '/merge_requests'
headers = {'PRIVATE-TOKEN': ci_job_token}
merge_requests = ""
try:
if os.environ['CI_JOB_TOKEN'] == ci_job_token:
headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']}
if os.environ['CI_JOB_TOKEN'] is not None:
headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']}
if os.environ['CI_JOB_TOKEN'] == ci_job_token:
headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']}
merge_requests = requests.get(url, headers=headers, data='')
merge_requests = merge_requests.json()
except:
pass
#print('[DEBUG] headers[{0}]'.format(headers))
merge_requests = requests.get(url, headers=headers, data='')
if not isinstance(merge_requests, list):
headers = {'PRIVATE-TOKEN': ci_job_token}
merge_requests = merge_requests.json()
merge_requests = requests.get(url, headers=headers, data='')
merge_requests = merge_requests.json()
#print('\n\nmerge_requests=[-{0}-][]\n\n\n\n\n'.format(merge_requests))
@ -73,28 +81,20 @@ mr_title = ''
mr_first_commit = ''
target_branch = ''
for mr in merge_requests:
if isinstance(merge_requests, list):
# print('\n\nMR=[-{0}-]'.format(mr))
if len(merge_requests) > 0:
if mr['source_branch'] == git_branch and str(mr['target_project_id']) == str(project_id) and str(mr['state']) == 'opened':
for mr in merge_requests:
if mr['source_branch'] == git_branch and str(mr['target_project_id']) == str(project_id) and str(mr['state']) == 'opened':
mr_title = mr['title']
mr_first_commit = mr['sha']
target_branch = mr['target_branch']
if get_mr_title:
print('{0}'.format(mr_title))
if get_target_branch:
print('{0}'.format(target_branch))
else:
if get_first_commit:
print('{0}'.format(mr_first_commit))
if get_mr_title:
print('{0}'.format(mr_title))
print('ci: No Merge Request found')