gitlab todo 항목 10개를 여는 함수

1 minute read

gitlab todo 기능 마음에 든다. 날 멘션(@mention) 하거나 담당자(assignee)로 설정했을 때, gitlab 시스템이 todo 목록으로 추가한다. 한눈에 내가 읽거나 답변해야 할 목록을 볼 수 있다. gitlab 기본 페이지로 해놓고 쓰고 있다.

매일 todo를 처리하다 보니 불편한 게 있다. todo 리스트에서 항목을 보고 완료 처리를 하기가 힘들다. 어떤 내용인지 파악이 안 되는 경우가 많아서다. 그래서 항상 해당 이슈(issue)나 머지 리퀘스트(merge request)를 열어보고 답변을 달거나 완료 처리를 한다. 매일 todo 개수가 50개는 넘는 것 같다. 이걸 하나하나 열어서 확인하고 완료 처리하는 게 귀찮다. 그래서 todo 항목 10개를 여는 emacs 함수를 만들었다.

(defun my-gitlab-open-todo ()
  (interactive)
  (let ((todos (my-gitlab--request-get (my-gitlab--build-request
                                        "todos"
                                        '(("per_page" 10))))))
    (dolist (elt todos)
      (browse-url (plist-get elt :target_url)))))

메인 함수다. my-gitlab-open-todo 함수를 호출하면 todo 항목 최대 10개를 크롬(chrome)으로 연다.

(defun my-gitlab--request-get (url)
  (let ((json-array-type 'list)
        (json-object-type 'plist)
        (json-key-type 'keyword))
    (with-temp-buffer
      (url-insert-file-contents url)
      (json-read))))

my-gitlab--request-get 함수는 HTTP get 메서드 응답을 json 포멧으로 리턴한다. with-temp-buffer 함수로 임시 버퍼를 만들고 url-insert-file-contents 함수로 HTTP 응답을 받아 버퍼에 삽입한다. 버퍼를 작업 공간으로 사용할 때마다 에디터 언어로 설계한 emacs lisp를 사용하고 있다는 걸 실감한다.

(defun my-gitlab--build-request (page properties)
  (when (not (boundp 'gitlab-private-key)) (throw 'gitlab-private-key "not bound"))
  (when (not (boundp 'gitlab-api-url)) (throw 'gitlab-api-url "not bound"))
  (format "%s/%s?%s"
          gitlab-api-url
          page
          (my-gitlab--build-params (cons `("private_token" ,gitlab-private-key) properties))))

(defun my-gitlab--build-params (params)
  (let (value '())
    (dolist (elt params value)
      (setq value
            (cons (format "%s=%s" (car elt) (cadr elt))
                  value)))
    (string-join value "&")))

my-gitlab--build-params 함수는 '(("state" "opened") ("milestones" "scooter")) 를 인자로 넘기면 "state=opened&milestones=scooter" query string으로 변경한다. my-gitlab--build-request 함수는 모두 조합한 url을 만든다. 프로젝트, 유저마다 달라지는 api url과 private key는 변수로 정의한다. 함수를 실행할 때, 없으면 예외를 던지게 했다.

my-gitlab-open-todo 함수를 호출하면 gitlab todo 10개가 웹브라우저로 열린다. 아주 편해졌다. ccd334f0fe 커밋에서 전체 코드를 볼 수 있다.

C-x C-s C-x C-c