forgejo: Support deletion of branches when a pull request is closed.
This commit is contained in:
parent
8e7da32f55
commit
254998a561
3 changed files with 29 additions and 3 deletions
|
|
@ -43,7 +43,8 @@
|
||||||
forgejo-pull-request-draft?
|
forgejo-pull-request-draft?
|
||||||
forgejo-pull-request-body
|
forgejo-pull-request-body
|
||||||
|
|
||||||
enqueue-job-for-pull-request))
|
enqueue-job-for-pull-request
|
||||||
|
mark-pull-request-branch-for-deletion))
|
||||||
|
|
||||||
;; The JSON data structures below were copied from Cuirass.
|
;; The JSON data structures below were copied from Cuirass.
|
||||||
|
|
||||||
|
|
@ -125,3 +126,22 @@
|
||||||
|
|
||||||
(enqueue-load-new-guix-revision-job conn repository-id
|
(enqueue-load-new-guix-revision-job conn repository-id
|
||||||
commit label))))
|
commit label))))
|
||||||
|
|
||||||
|
(define (mark-pull-request-branch-for-deletion conn pull-request)
|
||||||
|
"Mark the branch associated with @var{pull-request}, a pull request being
|
||||||
|
closed, for deletion."
|
||||||
|
(let* ((url (forgejo-pull-request-url pull-request))
|
||||||
|
(repository-id (git-repository-url->git-repository-id
|
||||||
|
conn url #:create-if-missing? #f)))
|
||||||
|
(when repository-id
|
||||||
|
(let* ((date (time-utc->date (current-time time-utc)))
|
||||||
|
(reference (forgejo-pull-request-head pull-request))
|
||||||
|
(branch (forgejo-repository-reference-ref reference))
|
||||||
|
(branch-id (git-branch-for-repository-and-name
|
||||||
|
conn repository-id branch)))
|
||||||
|
(when branch-id
|
||||||
|
;; Insert a commit entry with the empty string: this is interpreted
|
||||||
|
;; as BRANCH-ID being a candidate for deletion.
|
||||||
|
(format #t "marking pull request branch ~s of ~s for deletion~%"
|
||||||
|
branch url)
|
||||||
|
(insert-git-commit-entry conn branch-id "" date))))))
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
('synchronized ;pull request is updated
|
('synchronized ;pull request is updated
|
||||||
(enqueue-job-for-pull-request conn pull-request))
|
(enqueue-job-for-pull-request conn pull-request))
|
||||||
('closed ;closed or merged
|
('closed ;closed or merged
|
||||||
#f)
|
(mark-pull-request-branch-for-deletion conn pull-request))
|
||||||
(_ ;other action
|
(_ ;other action
|
||||||
(render-json '((error . "unknown action"))
|
(render-json '((error . "unknown action"))
|
||||||
#:code 404)))))))
|
#:code 404)))))))
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,13 @@
|
||||||
(enqueue-job-for-pull-request conn pull)))
|
(enqueue-job-for-pull-request conn pull)))
|
||||||
|
|
||||||
(test-assert "git-commit-exists?, new commit"
|
(test-assert "git-commit-exists?, new commit"
|
||||||
(git-commit-exists? conn pull-request-new-commit)))
|
(git-commit-exists? conn pull-request-new-commit))
|
||||||
|
|
||||||
|
(test-assert "mark-pull-request-branch-for-deletion"
|
||||||
|
(let* ((event (json->forgejo-pull-request-event
|
||||||
|
pull-request-event-json))
|
||||||
|
(pull (forgejo-pull-request-event-pull-request event)))
|
||||||
|
(mark-pull-request-branch-for-deletion conn pull))))
|
||||||
|
|
||||||
#:always-rollback? #t)))
|
#:always-rollback? #t)))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue