diff options
| author | Carlos Konstanski <carlos.konstanski@olo.com> | 2025-10-10 18:07:22 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-10 18:07:22 -0600 |
| commit | 58a1ff2ddb976778b6c9a597f61f871d383a040e (patch) | |
| tree | 1c8df71d4c085eb445aedd0e31766b319c9186a9 /lisp/git/git.lisp | |
| parent | e6cb6651be5744b8f2d7eb67333d9647611ab3d4 (diff) | |
| parent | 06afded48d852e7fa89b8e25938640cbab510e32 (diff) | |
Merge pull request #7 from ololabs/inf-18037-manage-git-checkouts-from-all-three-organizations
[INF-18037] Manage git checkouts from all three organizations
Diffstat (limited to 'lisp/git/git.lisp')
| -rw-r--r-- | lisp/git/git.lisp | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/lisp/git/git.lisp b/lisp/git/git.lisp index 1aa8eb0..a73a5d3 100644 --- a/lisp/git/git.lisp +++ b/lisp/git/git.lisp @@ -35,39 +35,43 @@ (defmethod bg-perform ((git-update git-update)) (let ((output (make-array '(0) :element-type 'character :fill-pointer 0 :adjustable t)) - (all-remotes-command "gh repo list ololabs -L 9999 --no-archived --json sshUrl | jq -M '.[].sshUrl'") - (all-locals-command (format nil "cd ~a ; find . -maxdepth 1 -type d" (pwd git-update))) + (github-orgs '("ololabs" "ololabs-geo" "omnivore")) + (all-locals-command (format nil "cd ~a ; find . -maxdepth 2 -type d" (pwd git-update))) all-remotes all-remote-dirs all-locals) - (setf all-remotes (sort (remove-if (lambda (item) - (or (org-ckons-core::match-it "CDN.git" item) - (org-ckons-core::match-it "terraform-github-import-playground.git" item) - (org-ckons-core::match-it "MvvmCross.git" item))) - (loop for remote in (org-ckons-core::shell-wrapper all-remotes-command) - collect (ppcre:regex-replace-all "\"" remote ""))) - 'string<)) - (setf all-remote-dirs (loop for remote in all-remotes - collect (subseq remote 23 (- (length remote) 4)))) - (setf all-locals (sort (set-difference (loop for dir in (org-ckons-core::shell-wrapper all-locals-command) - when (not (string= dir ".")) - collect (if (string= "./" (subseq dir 0 2)) - (subseq dir 2) - dir)) - (exclude-dirs git-update) - :test 'string=) - 'string<)) + (loop for org in github-orgs + do (org-ckons-core::add-to-list all-remotes + (sort (remove-if (lambda (item) + (or (org-ckons-core::match-it "CDN.git" item) + (org-ckons-core::match-it "terraform-github-import-playground.git" item) + (org-ckons-core::match-it "MvvmCross.git" item))) + (loop for remote in (org-ckons-core::shell-wrapper (format nil "gh repo list ~a -L 9999 --no-archived --json sshUrl | jq -M '.[].sshUrl'" org)) + collect (ppcre:regex-replace-all "\"" remote ""))) + 'string<)) + (org-ckons-core::add-to-list all-remote-dirs + (loop for remote in all-remotes + collect (subseq remote 15 (- (length remote) 4)))) + (org-ckons-core::add-to-list all-locals + (sort (set-difference (loop for dir in (org-ckons-core::shell-wrapper all-locals-command) + when (org-ckons-core::match-it "^\./.*/.*$" dir) + collect (subseq dir 2)) + (exclude-dirs git-update) + :test 'string=) + 'string<))) (with-output-to-string (stream output) - (format stream "~a~%~%" all-remotes) - (loop for dir in (set-difference all-remote-dirs all-locals :test 'string=) - do (progn - (format stream "Deleting ~a/~a~%" (pwd git-update) dir) - (org-ckons-core::shell-wrapper (format nil "rm -rf ~a/~a~%" (pwd git-update) dir)))) - (loop for remote in all-remotes - do (enqueue *queue-git* (make-instance 'git-update-task - :stdout (stdout git-update) - :remote remote))) - (format stream "~%~%~%")) + (if all-remotes + (progn + (format stream "~a~%~%~%" all-remotes) + (loop for dir in (set-difference all-remote-dirs all-locals :test 'string=) + do (format stream "Deleting ~a/~a~%" (pwd git-update) dir) + (org-ckons-core::shell-wrapper (format nil "rm -rf ~a/~a~%" (pwd git-update) dir))) + (loop for remote in all-remotes + do (enqueue *queue-git* (make-instance 'git-update-task + :stdout (stdout git-update) + :remote remote))) + (format stream "~%~%~%")) + (format stream "No remotes found. Something went wrong. Aborting.~%"))) (with-open-file (stream (stdout git-update) :direction :output :if-exists :append :if-does-not-exist :create) (format stream output)))) @@ -76,15 +80,17 @@ (defmethod bg-perform ((git-update-task git-update-task)) (let* ((output (make-array '(0) :element-type 'character :fill-pointer 0 :adjustable t)) - (dir (subseq (remote git-update-task) 23 (- (length (remote git-update-task)) 4))) - (status-command (format nil "cd ~a/~a ; git status" (pwd git-update-task) dir)) - (fetch-command (format nil "cd ~a/~a ; git fetch --prune" (pwd git-update-task) dir)) - (branch-command (format nil "cd ~a/~a ; PAGER=cat git branch | grep -F '*' | awk '{print $2}'" (pwd git-update-task) dir)) - (clone-command (format nil "cd ~a ; git clone ~a" (pwd git-update-task) (remote git-update-task)))) + (fulldir (subseq (remote git-update-task) 15 (- (length (remote git-update-task)) 4))) + (org (first (ppcre:split "/" fulldir))) + (repo (second (ppcre:split "/" fulldir))) + (status-command (format nil "cd ~a/~a ; git status" (pwd git-update-task) fulldir)) + (fetch-command (format nil "cd ~a/~a ; git fetch --prune" (pwd git-update-task) fulldir)) + (branch-command (format nil "cd ~a/~a ; PAGER=cat git branch | grep -F '*' | awk '{print $2}'" (pwd git-update-task) fulldir)) + (clone-command (format nil "cd ~a ; mkdir -p ~a ; cd ~a ; gh repo clone ~a" (pwd git-update-task) org org fulldir))) (with-output-to-string (stream output) - (if (probe-file (format nil "~a/~a" (pwd git-update-task) dir)) + (if (probe-file (format nil "~a/~a" (pwd git-update-task) fulldir)) (progn - (format stream "Checking ~a~%" dir) + (format stream "Checking ~a~%" fulldir) (multiple-value-bind (stdout return-code) (shell-wrapper-as-string status-command) (format stream "~a~%" stdout) @@ -93,11 +99,11 @@ (let ((branch (string-trim '(#\Space #\Tab #\Newline) (shell-wrapper-as-string branch-command)))) (if (position branch '("main" "develop" "development" "master") :test 'string=) (progn - (format stream "Updating repo ~a on branch ~a~%" dir branch) - (format stream (shell-wrapper-as-string (format nil "cd ~a/~a ; git pull origin ~a" (pwd git-update-task) dir branch)))) - (format stream "~a not pulled because it is on branch ~a~%" dir branch)))))) + (format stream "Updating repo ~a on branch ~a~%" fulldir branch) + (format stream (shell-wrapper-as-string (format nil "cd ~a/~a ; git pull origin ~a" (pwd git-update-task) fulldir branch)))) + (format stream "~a not pulled because it is on branch ~a~%" fulldir branch)))))) (progn - (format stream "Cloning ~a~%" dir) + (format stream "Cloning ~a~%" fulldir) (format stream (shell-wrapper-as-string clone-command)))) (format stream "~%~%~%")) (with-open-file (stream (stdout git-update-task) :direction :output :if-exists :append :if-does-not-exist :create) |
