this fixes the custom clone step for forks with outdated default branch

This commit is contained in:
Willy Kloucek
2022-01-20 08:22:48 +01:00
parent ced35e3a9e
commit 7e4c356f49

View File

@@ -357,7 +357,12 @@ def uploadScanResults(ctx):
"SONAR_PULL_REQUEST_KEY": "%s" % (ctx.build.ref.replace("refs/pull/", "").split("/")[0]),
})
repo_slug = ctx.build.source_repo if ctx.build.source_repo else ctx.repo.slug
fork_handling = []
if ctx.build.source_repo:
fork_handling = [
"git remote add fork https://github.com/%s.git" % (ctx.build.source_repo),
"git pull fork",
]
return {
"kind": "pipeline",
@@ -375,9 +380,13 @@ def uploadScanResults(ctx):
"name": "clone",
"image": "alpine/git:latest",
"commands": [
"git clone https://github.com/%s.git ." % (repo_slug),
"git checkout $DRONE_COMMIT",
],
# Always use the owncloud/ocis repository as base to have an up to date default branch.
# This is needed for the skipIfUnchanged step, since it references a commit on master (which could be absent on a fork)
"git clone https://github.com/%s.git ." % (ctx.repo.slug),
] + fork_handling +
[
"git checkout $DRONE_COMMIT",
],
},
] + skipIfUnchanged(ctx, "unit-tests") + [
{