블로그 이전했습니다!
https://computasha.com/Git/improvement/github+label+sync%2C+깃허브+라벨+쉽게+적용하기




새로운 레포를 만들 때마다 라벨을 다시 만드려니 너무 귀찮았다. 수작업 그자체..
이걸 어떻게 해결할까 고민하다 github label sync 라는 라이브러리를 찾았다!

github label sync는 label 템플릿을 만들어서 관리하고 이를 repo에 바로 적용할 수 있게 도와주는 라이브러리이다.

설치 방법과 repo에 적용하면서 겪은 에러까지 공유하고자 한다.

Financial-Times/github-label-sync github



1. ✅ 요구사항

  • Node.js가 설치되어 있어야 한다.
  • 레포에 접근하기 위해 GitHub access token이 필요하다.
  • labels.json 파일이 필요하다. (아래 labels.json 설정 참고)



2. 🏷️ labels.json 설정

새롭게 적용할 label config 인 labels.json 을 정의해야 한다. + YAML 파일도 가능
(default 이름은 labels.json지만, 원하는 대로 변경해도 된다)

label의 namecolordescriptionaliases 를 정의할 수 있다. 공식 repo 예시


나의 labels.json

기막힌 라벨링 방법 추천 부탁드립니다..

[
	{
		"name": "API",
		"color": "0052CC",
		"description": "type : API 관련 작업"
	},
	{
		"name": "bug",
		"color": "d73a4a",
		"description": "type : 버그 발생"
	},
	{
		"name": "bugfix",
		"color": "E99695",
		"description": "type : 버그 해결"
	},
	{
		"name": "cleanup",
		"color": "FEF2C0",
		"description": "type : 코드를 깔끔하게 정리하는 경우 (리팩토링과 구별)"
	},
	{
		"name": "doc",
		"color": "747B8B",
		"description": "type : 문서 수정"
	},
	{
		"name": "draft",
		"color": "0E8A16",
		"description": "type : draft 상태 PR"
	},
	{
		"name": "feat",
		"color": "a2eeef",
		"description": "type : 구현, 개선 사항"
	},
	{
		"name": "question",
		"color": "d876e3",
		"description": "type : 질문, 질문 해결 시 이슈 닫음"
	},
	{
		"name": "refactoring",
		"color": "e4e669",
		"description": "type : 코드 내부 작동 방식 변경"
	},
	{
		"name": "setting",
		"color": "ffffff",
		"description": "type : 프로젝트 세팅 관련"
	},
	{
		"name": "test",
		"color": "008672",
		"description": "type : 테스트 코드"
	}
]




3. 👾 라이브러리 설치 및 사용법

(Command-Line Interface)

설치

npm 을 통해 GitHub Label Sync 설치 :

npm install -g github-label-sync

github-label-sync command-line tool 설명 :

사용법: github-label-sync [options] <repository>

Options:

  -h, --help                  도움말 확인
  -V, --version               버전 확인
  -a, --access-token <token>  GitHub access token 
  -l, --labels <path>         label 파일 경로 (Default: labels.json)
  -d, --dry-run               변경 사항 체크용 옵션. 실제로 Github에 반영되지는 않음.
  -A, --allow-added-labels    repo의 기존 label을 삭제하지 않고 추가, 수정 사항만 적용함.




사용법

repo에서 GitHub Label Sync 실행 (로컬의 labels.json 파일 사용) :

github-label-sync --access-token [액세스토큰] [계정명]/[repo 이름]

실행 예시 :

github-label-sync --access-token abcdefg1234556789 compuTasha/test

Syncing labels for "compuTasha/test"
Validating provided labels
Fetching labels from GitHub
> Changed: the "bug" label in the repo is out of date. It will be updated to "bug" with color "#d73a4a" and description "type : 버그 발생".
> Missing: the "bugfix" label is missing from the repo. It will be created.
> Added: the "feat" label in the repo is not expected. It will be deleted.
Applying label changes, please wait…
Labels updated



다른 경로의 label config 파일을 사용해서 GitHub Label Sync 실행 (JSON 혹은 YAML 파일) :

github-label-sync --access-token [액세스토큰] --labels my-labels.json [계정명]/[repo 이름]
github-label-sync --access-token [액세스토큰] --labels my-labels.yml [계정명]/[repo 이름]



—dry-run 옵션을 사용하면, GitHub API에 “read” 요청만 한다.
즉, repo에 실제로 반영하기 전에 변경사항을 확인할 수 있다.

github-label-sync --access-token [액세스토큰] --dry-run [계정명]/[repo 이름]



기본적으로 GitHub label sync 실행 시 labels.json에 없는 label은 삭제된다.
그러나 —allow-added-labels 옵션을 사용하면, 기존 라벨을 삭제하지 않고 새로운 label을 추가하거나 수정된 사항만 적용한다.

github-label-sync --access-token [액세스토큰] --allow-added-labels [계정명]/[repo 이름]




4. 🚨 에러 발생

404 not found 에러가 발생하는 경우

  1. token 권한을 설정할 때, repo와 workflow를 추가 안 한 경우.
    GitHub access token 에서 권한을 변경하면 된다.

    참고 : https://github.com/Financial-Times/github-label-sync/issues/48


  1. organization 내의 repo인 경우.
    명령어에 계정명 대신 organization 이름을 넣으면 된다.
github-label-sync --access-token [액세스토큰] [organization 이름]/[repo 이름]



이제 모두들 편하게 라벨 추가하세요~~~~~~