From 159a0027ff50baa7e6d21cec0e75153f52dccf64 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 27 Dec 2024 20:04:25 -0500 Subject: [PATCH] theoretically works, BUT: how do I add a room *to a space*? how do I give control of a room to someone else? --- scripts/beefhaving_video.groovy | 164 ++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 74 deletions(-) diff --git a/scripts/beefhaving_video.groovy b/scripts/beefhaving_video.groovy index 5384bc9..d22dbf9 100644 --- a/scripts/beefhaving_video.groovy +++ b/scripts/beefhaving_video.groovy @@ -5,93 +5,109 @@ pipeline { string(name: 'videodesc', description: "video description") } environment { - GITEATOKEN = credentials('d0e86441-2157-405f-8539-a9a9010c6ecf') - JENKINSMATRIX=credentials('040b63d1-2f14-4692-badb-114bddd7c5a5') + JENKINSONGITEA=credentials('d0e86441-2157-405f-8539-a9a9010c6ecf') + JENKINSONMATRIXTOKEN=credentials('17d18fd7-29eb-4957-9532-ce42aaa9b4ec') } - + stages { stage("environment setup") { - steps{ - script{ - if (videoname.isEmpty()) { - error("videoname mandatory") - } - if (videoname.contains(' ')) { - error("videoname cannot have spaces. try dashes.") - } - } - } + steps{ + script{ + if (videoname.isEmpty()) { + error("videoname mandatory") + } + if (videoname.contains(' ')) { + error("videoname cannot have spaces. try dashes.") + } + } + } } stage("create gitea project"){ steps{ - sh """ - curl -X 'POST' \ - 'https://gitea.arg.rip/api/v1/repos/beefhavers/_videotemplate/generate' \ - -H 'accept: application/json' \ - -H 'Authorization: token ${env.GITEATOKEN}' \ - -H 'Content-Type: application/json' \ - -d '{ - "description": "${videodesc}", - "git_content": true, - "git_hooks": true, - "labels": true, - "name": "${videoname}", - "owner": "beefhavers", - "private": false, - "protected_branch": true, - "topics": true, - "webhooks": true - }' - """ + script{ + env.giteaCreateEvent=sh(returnStdout: true, script: """ + curl -X 'POST' \ + 'https://gitea.arg.rip/api/v1/repos/beefhavers/_videotemplate/generate' \ + -H 'accept: application/json' \ + -H 'Authorization: token ${env.JENKINSONGITEA}' \ + -H 'Content-Type: application/json' \ + -d '{ + "description": "${videodesc}", + "git_content": true, + "git_hooks": true, + "labels": true, + "name": "${videoname}", + "owner": "beefhavers", + "private": false, + "protected_branch": true, + "topics": true, + "webhooks": true + }' + """).trim() + if (!env.giteaCreateEvent?.trim()) { + error "couldn't make gitea repo, apparently" + } + } } } stage("create matrix room"){ - steps{ - env.roomId=sh(returnStdout: true, script: """ - curl -X 'POST' \ - 'https://greyn.club:8448/_matrix/client/v3/createRoom' \ - -H 'accept: application/json' \ - -H 'Authorization: Bearer ${JENKINSMATRIX}}' \ - -H 'Content-Type: application/json' \ - -d '{ - "creation_content": { - "m.federate": false - }, - "name": "${videoname}", - "preset": "public_chat", - "invite": ["@adam:greyn.club", "@gitea:greyn.club"], - "topic": "[link to gitea project]" - }' | jq .room_id - """ - ).trim() - } + steps{ + script{ + env.roomcreationevent=sh(returnStdout: true, script: """ + curl -X 'POST' \ + 'https://greyn.club:8448/_matrix/client/v3/createRoom' \ + -H 'accept: application/json' \ + -H 'Authorization: Bearer ${JENKINSONMATRIXTOKEN}' \ + -H 'Content-Type: application/json' \ + -d '{ + "creation_content": { + "m.federate": false + }, + "name": "${videoname}", + "preset": "public_chat", + "invite": ["@adam:greyn.club", "@gitea:greyn.club"], + "topic": "[link to gitea project]" + }' + """ + ).trim() + if (!env.roomcreationevent?.trim()) { + error "couldn't make matrix room, apparently" + } + echo "roomcreationevent:" + echo env.roomcreationevent + env.room_id = sh(returnStdout: true, script: "${env.roomcreationevent} | jq .room_id").trim() + if(!env.room_id?.trim()){ + error "couldn't make matrix room, apparently" + } + } + } } stage("link gitea webhook"){ - steps{ - sh """ - curl -X 'GET' 'https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks' \ - -H 'accept: application/json' \ - -H 'authorization: token ${env.GITEATOKEN}' \ - >reporesponse.json - """ + steps{ + sh """ + curl -X 'GET' 'https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks' \ + -H 'accept: application/json' \ + -H 'authorization: token ${env.JENKINSONGITEA}' \ + >reporesponse.json + """ - sh """ - curl -X 'PATCH' 'https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks' \ - -H 'accept: application/json' \ - -H 'authorization: token ${env.GITEATOKEN}' \ + sh """ + curl -X 'PATCH' 'https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks' \ + -H 'accept: application/json' \ + -H 'authorization: token ${env.JENKINSONGITEA}' \ -H 'Content-Type: application/json' \ - -d '{ - "active": true, - "authorization_header": \$(cat reporesponse.json | jq .[0].authorization_header), - "branch_filter": "*", - "config": { - "content_type": "json", - "url": "https://greyn.club:8448/_matrix/client/r0/rooms/\$(echo ${env.roomId} | sed 's/!/%21/')/send/m.room.message" - }, - "events": \$(cat reporesponse.json | jq .[0].events) - }' - """ - } + -d '{ + "active": true, + "authorization_header": \$(cat reporesponse.json | jq .[0].authorization_header), + "branch_filter": "*", + "config": { + "content_type": "json", + "url": "https://greyn.club:8448/_matrix/client/r0/rooms/\$(echo ${env.room_id} | sed 's/!/%21/')/send/m.room.message" + }, + "events": \$(cat reporesponse.json | jq .[0].events) + }' + """ + } } } }