; A function that takes an argument of a forgerie-core:merge-request and
; returns a string that will be appended to the description of created merge requests.
;
; Useful to create backlinks to the previous system, or addition migration information
(setf forgerie-gitlab:*merge-request-suffix* (lambda (mr) (format nil "~%~%Migrated from D~A ([original](https://forge.softwareheritage.org/D~A))" (forgerie-core:merge-request-id mr) (forgerie-core:merge-request-id mr))))

; A function that takes an argument of a forgerie-core:ticket and
; returns a string that will be appended to the description of created tickets (issues).
;
; Useful to create backlinks to the previous system, or addition migration information
(setf forgerie-gitlab:*ticket-suffix* (lambda (ticket) (format nil "~%~%Migrated from T~A ([original](https://forge.softwareheritage.org/T~A))" (forgerie-core:ticket-id ticket) (forgerie-core:ticket-id ticket))))

;; Namespace structure
;; - Group: Software Heritage
;;     - repos: python projects in a flat namespace
;; - Group: Infrastructure
;;     - Group: Jenkins
;;         - repos: jenkins-related repos
;;     - Group: Puppet
;;         - repos: our own puppet repos (puppet-swh-*)
;;         - Group: puppet dependencies
;;     - Group: Provisioning
;;     - Group: git-annex
;; - Group: Teams
;;     - Group: staff
;;     - Group: HR
;; - Group: Research
;;     - repos: papers

(setf forgerie-gitlab:*group-structure*
   '((:name "Software Heritage" :path "software-heritage")
     (:name "Infrastructure" :path "infrastructure")
      (:name "Jenkins" :path "jenkins" :parent "infrastructure")
      (:name "Puppet" :path "puppet" :parent "infrastructure")
       (:name "Dependencies" :path "dependencies" :parent "infrastructure/puppet")
      (:name "Provisioning" :path "provisioning" :parent "infrastructure")
     (:name "Teams" :path "teams")
      (:name "Staff" :path "staff" :parent "teams")
      (:name "System Administrators" :path "sysadmin" :parent "teams")
      (:name "Interns" :path "interns" :parent "teams")
     (:name "Research" :path "research")))

(setf forgerie-gitlab:*namespace-for-repo*
 (lambda (repo)
   (let*
    ((repo-slug (forgerie-core:vc-repository-slug repo))
     (repo-tags
      (remove-duplicates
       (apply #'append
        (mapcar
         #'forgerie-core:project-tags
         (append
          (forgerie-core:vc-repository-primary-projects repo)
          (forgerie-core:vc-repository-projects repo))))
       :test #'string=)))
    (cond
     ((str:starts-with? "puppet-swh-" repo-slug) "infrastructure/puppet")
     ((string= "puppet-environment" repo-slug) "infrastructure/puppet")
     ((str:starts-with? "puppet-" repo-slug) "infrastructure/puppet/dependencies")
     ((find "language_python" repo-tags :test #'string=) "software-heritage")
     (t nil)))))

   ;; "swh-sysadmin-provisioning"
   ;; "getsentry-onpremise"
   ;; "swh-grafana-dashboards"
   ;; "swh-ansible"
   ;; "sysadm-environment"


;; (setf forgerie-gitlab:*single-project* "k8s-clusters-conf")