2022-10-10 11:56:55 +02:00
|
|
|
def commentPullRequest(String repo, String issueId, String comment, Integer commentIndex = -1) {
|
2022-05-17 14:34:21 +02:00
|
|
|
comment = comment.replaceAll('"', '\\"')
|
|
|
|
withCredentials([
|
|
|
|
string(credentialsId: 'GITEA_JENKINS_PERSONAL_TOKEN', variable: 'GITEA_TOKEN'),
|
|
|
|
]) {
|
2022-09-05 10:15:03 +02:00
|
|
|
writeFile(file: '.prComment', text: comment)
|
2022-05-17 14:34:21 +02:00
|
|
|
sh """#!/bin/bash
|
|
|
|
set -xeo pipefail
|
|
|
|
|
2022-10-10 11:56:55 +02:00
|
|
|
previous_comment_id=null
|
|
|
|
|
|
|
|
if [ "${commentIndex}" != "-1" ]; then
|
|
|
|
# Récupération si il existe du commentaire existant
|
|
|
|
previous_comment_id=\$(curl -v --fail \
|
|
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
https://forge.cadoles.com/api/v1/repos/${repo}/issues/${issueId}/comments \
|
|
|
|
| jq -c '[ .[] | select(.user.login=="jenkins") ] | .[${commentIndex}] | .id' \
|
|
|
|
)
|
|
|
|
fi
|
2022-05-17 14:34:21 +02:00
|
|
|
|
|
|
|
# Génération du payload pour l'API Gitea
|
|
|
|
echo '{}' | jq -c --rawfile body .prComment '.body = \$body' > payload.json
|
|
|
|
|
|
|
|
if [[ "\$previous_comment_id" == "null" ]]; then
|
|
|
|
# Création du commentaire via l'API Gitea
|
|
|
|
curl -v --fail \
|
|
|
|
-XPOST \
|
|
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d @payload.json \
|
|
|
|
https://forge.cadoles.com/api/v1/repos/${repo}/issues/${issueId}/comments
|
|
|
|
else
|
|
|
|
# Modification du commentaire existant
|
|
|
|
curl -v --fail \
|
|
|
|
-XPATCH \
|
|
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d @payload.json \
|
|
|
|
https://forge.cadoles.com/api/v1/repos/${repo}/issues/comments/\$previous_comment_id
|
|
|
|
fi
|
|
|
|
"""
|
|
|
|
}
|
2022-09-05 10:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Effectue une "release" sur Gitea pour le <ORG>/<PROJET> donné.
|
2022-10-22 00:49:11 +02:00
|
|
|
void release(String credentialsId, String org, String project, Map options = [:]) {
|
|
|
|
Boolean isDraft = options.get('isDraft', false)
|
|
|
|
String baseUrl = options.get('baseUrl', 'https://forge.cadoles.com')
|
|
|
|
String defaultVersion = sh(returnStdout: true, script: 'git describe --always').trim()
|
|
|
|
String releaseVersion = options.get('releaseVersion', defaultVersion)
|
|
|
|
String releaseName = options.get('releaseName', releaseVersion)
|
|
|
|
String commitishTarget = options.get('commitishTarget', env.GIT_COMMIT)
|
|
|
|
|
|
|
|
Boolean defaultIsPrerelease = true
|
2022-09-05 10:15:03 +02:00
|
|
|
try {
|
|
|
|
sh(script: "git describe --exact-match ${GIT_COMMIT}")
|
|
|
|
defaultIsPrerelease = false
|
|
|
|
} catch (err) {
|
|
|
|
println "Could not find tag associated with commit '${GIT_COMMIT}' ! Using 'prerelease' as default."
|
|
|
|
}
|
|
|
|
|
2022-10-22 00:49:11 +02:00
|
|
|
Boolean isPrerelease = options.get('isPrerelease', defaultIsPrerelease)
|
|
|
|
String body = options.get('body', '')
|
|
|
|
List<String> attachments = options.get('attachments', [])
|
2022-09-05 10:15:03 +02:00
|
|
|
|
2022-10-22 00:49:11 +02:00
|
|
|
String scriptTempDir = ".gitea-release-script-${System.currentTimeMillis()}"
|
2022-09-05 10:15:03 +02:00
|
|
|
sh("mkdir -p '${scriptTempDir}'")
|
|
|
|
|
2022-10-22 00:49:11 +02:00
|
|
|
String giteaReleaseScript = "${scriptTempDir}/gitea-release.sh"
|
2022-09-05 10:15:03 +02:00
|
|
|
|
2022-10-22 00:49:11 +02:00
|
|
|
String giteaReleaseScriptContent = libraryResource 'com/cadoles/gitea/gitea-release.sh'
|
2022-09-05 10:15:03 +02:00
|
|
|
writeFile file: giteaReleaseScript, text:giteaReleaseScriptContent
|
|
|
|
sh("chmod +x '${giteaReleaseScript}'")
|
|
|
|
|
|
|
|
try {
|
|
|
|
withCredentials([
|
|
|
|
usernamePassword(
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
usernameVariable: 'GITEA_RELEASE_USERNAME',
|
|
|
|
passwordVariable: 'GITEA_RELEASE_PASSWORD'
|
|
|
|
)
|
|
|
|
]) {
|
|
|
|
sh """
|
|
|
|
export GITEA_RELEASE_PROJECT="${project}"
|
|
|
|
export GITEA_RELEASE_ORG="${org}"
|
|
|
|
export GITEA_RELEASE_BASE_URL="${baseUrl}"
|
|
|
|
export GITEA_RELEASE_VERSION="${releaseVersion}"
|
2022-09-30 17:27:42 +02:00
|
|
|
export GITEA_RELEASE_NAME="${releaseName}"
|
2022-09-05 10:15:03 +02:00
|
|
|
export GITEA_RELEASE_COMMITISH_TARGET="${commitishTarget}"
|
|
|
|
export GITEA_RELEASE_IS_DRAFT="${isDraft}"
|
|
|
|
export GITEA_RELEASE_IS_PRERELEASE="${isPrerelease}"
|
|
|
|
export GITEA_RELEASE_BODY="${body}"
|
|
|
|
export GITEA_RELEASE_ATTACHMENTS="${attachments.join(' ')}"
|
|
|
|
|
|
|
|
${giteaReleaseScript}
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
dir(scriptTempDir) {
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 00:49:11 +02:00
|
|
|
|
|
|
|
// Télécharge les fichiers associés à une "version" publiée sur un projet Gitea
|
|
|
|
void download(String credentialsId, String org, String project, Map options = [:]) {
|
|
|
|
String baseUrl = options.get('baseUrl', 'https://forge.cadoles.com')
|
|
|
|
String releaseName = options.get('releaseName', 'latest')
|
|
|
|
String outputDir = options.get('outputDir', 'gitea-dl')
|
|
|
|
|
|
|
|
String scriptTempDir = ".gitea-download-script-${System.currentTimeMillis()}"
|
|
|
|
sh("mkdir -p '${scriptTempDir}'")
|
|
|
|
|
|
|
|
String giteaDownloadScript = "${scriptTempDir}/gitea-download.sh"
|
|
|
|
|
|
|
|
String giteaDownloadScriptContent = libraryResource 'com/cadoles/gitea/gitea-download.sh'
|
|
|
|
writeFile file: giteaDownloadScript, text:giteaDownloadScriptContent
|
|
|
|
sh("chmod +x '${giteaDownloadScript}'")
|
|
|
|
|
|
|
|
try {
|
|
|
|
withCredentials([
|
|
|
|
usernamePassword(
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
usernameVariable: 'GITEA_DOWNLOAD_USERNAME',
|
|
|
|
passwordVariable: 'GITEA_DOWNLOAD_PASSWORD'
|
|
|
|
)
|
|
|
|
]) {
|
|
|
|
sh """
|
|
|
|
export GITEA_DOWNLOAD_PROJECT="${project}"
|
|
|
|
export GITEA_DOWNLOAD_ORG="${org}"
|
|
|
|
export GITEA_DOWNLOAD_BASE_URL="${baseUrl}"
|
|
|
|
export GITEA_DOWNLOAD_RELEASE_NAME="${releaseName}"
|
|
|
|
export GITEA_DOWNLOAD_TARGET_DIRECTORY="${outputDir}"
|
|
|
|
|
|
|
|
${giteaDownloadScript}
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
dir(scriptTempDir) {
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|