mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 12:44:33 +02:00
fix the bug that will cause sonarqube fail when got issue to report but can't get CI_MERGE_REQUEST_IID because it's not a MR pipeline
This commit is contained in:
31
tools/ci/ci_get_latest_mr_iid.py
Normal file
31
tools/ci/ci_get_latest_mr_iid.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# internal use only for CI
|
||||||
|
# get latest MR IID by source branch
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
from gitlab_api import Gitlab
|
||||||
|
|
||||||
|
|
||||||
|
def get_MR_IID_by_source_branch(source_branch):
|
||||||
|
if not source_branch:
|
||||||
|
return ''
|
||||||
|
gl = Gitlab(os.getenv('CI_PROJECT_ID'))
|
||||||
|
if not gl.project:
|
||||||
|
return ''
|
||||||
|
mrs = gl.project.mergerequests.list(state='opened', source_branch=source_branch)
|
||||||
|
if mrs:
|
||||||
|
mr = mrs[0] # one source branch can only have one opened MR at one moment
|
||||||
|
return mr.iid
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Get the latest MR IID by source branch, if not found, return empty string')
|
||||||
|
parser.add_argument('source_branch', nargs='?', help='source_branch') # won't fail if it's empty
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(get_MR_IID_by_source_branch(args.source_branch))
|
@@ -447,7 +447,11 @@ code_quality_check:
|
|||||||
- clang_tidy_check_regular
|
- clang_tidy_check_regular
|
||||||
only:
|
only:
|
||||||
- triggers
|
- triggers
|
||||||
|
allow_failure: true
|
||||||
script:
|
script:
|
||||||
|
- export CI_MERGE_REQUEST_IID=`python ${CI_PROJECT_DIR}/tools/ci/ci_get_latest_mr_iid.py ${CI_COMMIT_BRANCH} | xargs`
|
||||||
|
# test if this branch have merge request, if not, exit 0
|
||||||
|
- test -n "$CI_MERGE_REQUEST_IID" || exit 0
|
||||||
- sonar-scanner
|
- sonar-scanner
|
||||||
-Dsonar.analysis.mode=preview
|
-Dsonar.analysis.mode=preview
|
||||||
-Dsonar.host.url=$SONAR_HOST_URL
|
-Dsonar.host.url=$SONAR_HOST_URL
|
||||||
|
Reference in New Issue
Block a user