Skip to content

Latest commit

ย 

History

History
582 lines (361 loc) ยท 15.6 KB

Collaborate with Git on Javascript and Node.js.md

File metadata and controls

582 lines (361 loc) ยท 15.6 KB

Javascript์™€ Node.js๋กœ Git์„ ํ†ตํ•ด ํ˜‘์—…ํ•˜๊ธฐ


ํ˜‘์—… ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Git์„ ์ž˜ ์จ์•ผํ•œ๋‹ค.

ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ฐ™์ด ์ž‘์—…ํ•˜๋ฉด์„œ ์ž์‹ ์—๊ฒŒ ์ฃผ์–ด์ง„ ํŒŒํŠธ์— ๋Œ€ํ•œ ์˜์—ญ์„ pull๊ณผ push ํ•  ๋•Œ ๋‹ค๋ฅธ ํŒ€์›๊ณผ ๊ผฌ์ด์ง€ ์•Š๋„๋ก branch๋ฅผ ๋‚˜๋ˆ„์–ด pull request ํ•˜๋Š” ๋“ฑ๋“ฑ..

ํ˜‘์—… ๊ณผ์ •์„ ์—ฐ์Šตํ•ด๋ณด์ž



Prerequisites

Required Description
Git We follow the GitHub Flow
Node.js 10.15.0 LTS
Yarn 1.12.3 or above

Git๊ณผ GitHub์„ ํ™œ์šฉํ•œ ํ˜‘์—… ๊ฐœ๋ฐœ

Git : ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ ์†Œ์Šค ์ฝ”๋“œ์˜ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ค๊ณ„๋œ ๋„๊ตฌ

GitHub : Git์˜ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ ์ œ๊ณตํ•จ. ์ด์Šˆ์™€ pull request๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ด€๋ฆฌ


Git ์ €์žฅ์†Œ ์ƒ์„ฑ

$ mkdir awesome-javascript
$ cd awesome-javascript
$ git init

GitHub ๊ณ„์ •์— ๊ฐ™์€ ์ด๋ฆ„์˜ ์ €์žฅ์†Œ๋ฅผ ์ƒ์„ฑํ•œ ํ›„, git remote ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์›๊ฒฉ ์ €์žฅ์†Œ ์ถ”๊ฐ€

$ git remote add origin 'Github ์ฃผ์†Œ'

GitHub์— ์ด์Šˆ ๋“ฑ๋กํ•˜๊ธฐ


์ด์Šˆ๋Š” ์™œ ๋“ฑ๋กํ•˜๋Š”๊ฑฐ์ฃ ?

์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ์— ์•ž์„œ, ์š”๊ตฌ์‚ฌํ•ญ์ด๋‚˜ ํ•ด๊ฒฐํ•  ๋ฌธ์ œ๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”

GitHub์˜ ์ด์Šˆ ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜๋ฉด ํ˜‘์—…ํ•˜๋Š” ๋™๋ฃŒ์™€ ์‰ฝ๊ฒŒ ๊ณต์œ ๊ฐ€ ๊ฐ€๋Šฅํ•จ


GitHub ์ €์žฅ์†Œ์˜ Issues ํƒญ์—์„œ New issue๋ฅผ ํด๋ฆญํ•ด์„œ ์ด์Šˆ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Œ


์ด์Šˆ์™€ pull request ์š”์ฒญ์— ์ž‘์„ฑํ•˜๋Š” ๊ธ€์˜ ํ˜•์‹์„ ํ…œํ”Œ๋ฆฟ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Œ

(ํ…œํ”Œ๋ฆฟ์€ ๋งˆํฌ๋‹ค์šด ํ˜•์‹)


์ˆจ๊ธด ํด๋”์ธ .github ํด๋”์—์„œ ์ด์Šˆ ํ…œํ”Œ๋ฆฟ๊ณผ pull request ํ…œํ”Œ๋ฆฟ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•

devops/github-templates ๋ธŒ๋žœ์น˜์— ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ  github์— ํ‘ธ์‹œํ•˜์ž

$ git checkout -b devops/github-templates
$ mkdir .github
$ touch .github/ISSUE_TEMPLATE.md # Create issue template
$ touch .github/PULL_REQUEST_TEMPLATE.md # Create pull request template
$ git add .
$ git commit -m ':memo: Add GitHub Templates'
$ git push -u origin devops/github-templates


Node.js์™€ Yarn์œผ๋กœ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •ํ•˜๊ธฐ


์˜ค๋Š˜๋‚  javascript๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค.

์ด๋•Œ git์„ ํ™œ์šฉํ•œ ํ˜‘์—… ํ™˜๊ฒฝ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ฝ”๋“œ ๊ฒ€์ฆ, ํ…Œ์ŠคํŠธ, ๋นŒ๋“œ, ๋ฐฐํฌ ๋“ฑ์˜ ๊ณผ์ •์—์„œ ๋งŒ๋‚˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐœ๋ฐœ ํ™˜๊ฒฝ๋„ ์„ค์ •ํ•ด์•ผ ํ•œ๋‹ค.

์ด๋•Œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด Node.js์™€ npm, yarn


Node.js์™€ npm : JavaScript๊ฐ€ ๊ฑฐ๋Œ€ํ•œ ์˜คํ”ˆ์†Œ์Šค ์ƒํƒœ๊ณ„๋ฅผ ํ™•๋ณดํ•˜๋Š” ๋ฐ ๊ฒฐ์ •์ ์ธ ์—ญํ• ์„ ํ•จ


Node.js๋Š” Google์ด V8 ์—”์ง„์œผ๋กœ ๋งŒ๋“  Javascript ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์œผ๋กœ ์˜ค๋Š˜๋‚  ์ƒ๋‹นํžˆ ๋งŽ์ด ์“ฐ์ด๋Š” ์ค‘!

npm์€ Node.js๋ฅผ ์„ค์น˜ํ•  ๋•Œ ํฌํ•จ๋˜๋Š”๋ฐ, ํŒจํ‚ค์ง€๋ฅผ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋‹ค์–‘ํ•œ ๋ช…๋ น์„ ์ œ๊ณตํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋„๊ตฌ๋ผ๊ณ  ๋ณด๋ฉด ๋œ๋‹ค.

yarn์€ ํŽ˜์ด์Šค๋ถ์ด ๊ฐœ๋ฐœํ•œ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋กœ, ๊ทœ๋ชจ๊ฐ€ ์ปค์ง€๋Š” ํ”„๋กœ์ ํŠธ์—์„œ npm์„ ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€ ๋ณด์•ˆ, ๋นŒ๋“œ ์„ฑ๋Šฅ ๋ฌธ์ œ๋ฅผ ๊ฒช๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํƒ„์ƒํ•จ


Node.js ์„ค์น˜ ํ›„, yarn์„ npm ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ „์—ญ์œผ๋กœ ์„ค์น˜ํ•˜์ž

$ npm install yarn -g

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ


yarn init ๋ช…๋ น์–ด ์‹คํ–‰

ํ”„๋กœ์ ํŠธ ๊ธฐ๋ณธ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์„ฑ๋จ


pakage.json ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

{
  "name": "awesome-javascript",
  "version": "1.0.0",
  "main": "index.js",
  "repository": "https://github.com/kim6394/awesome-javascript.git",
  "author": "gyuseok <gyuseok6394@gmail.com>",
  "license": "MIT"
}

์ด ํŒŒ์ผ์€ ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค.

์ด ํŒŒ์ผ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์†์„ฑ์€ dependencies๋กœ, ํ”„๋กœ์ ํŠธ์™€ ํŒจํ‚ค์ง€ ๊ฐ„์˜ ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

yarn์˜ cli ๋ช…๋ น์–ด๋กœ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๋ฉด package.json ํŒŒ์ผ์˜ dependencies ์†์„ฑ์ด ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝ๋จ

node-fetch ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•ด๋ณด์ž

$ yarn add node-fetch

pakage.json์•ˆ์— ์•„๋ž˜์™€ ๊ฐ™์€ ๋‚ด์šฉ์ด ์ถ”๊ฐ€๋œ๋‹ค.

"dependencies": {
    "node-fetch": "^2.6.0"
}

์ถ”๊ฐ€๋กœ ์ƒ์„ฑ๋œ yarn.lock ํŒŒ์ผ์€ ๋ญ”๊ฐ€์š”?

์•ฑ์„ ๊ฐœ๋ฐœํ•˜๋Š” ๋„์ค‘ ํ˜น์€ ๋ฐฐํฌํ•  ๋•Œ ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํŒจํ‚ค์ง€๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ๋˜ํ•œ ํ˜‘์—…ํ•˜๋Š” ๋™๋ฃŒ๋“ค๋งˆ๋‹ค ๋‹ค๋ฅธ ๋ฒ„์ „์˜ ํŒจํ‚ค์ง€๊ฐ€ ์„ค์น˜๋  ์ˆ˜๋„ ์žˆ๋‹ค.

yarn์€ ๋ชจ๋“  ์‹œ์Šคํ…œ์—์„œ ํŒจํ‚ค์ง€ ๋ฒ„์ „์„ ์ผ๊ด€๋˜๊ฒŒ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด yarn.lock ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ ์ตœ์ƒ์œ„ ํด๋”์— ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•จ.

(์‚ฌ์šฉ์ž๋Š” ์ด ํŒŒ์ผ์„ ์ง์ ‘ ์ˆ˜์ •ํ•˜๋ฉด ์•ˆ๋จ. ์˜ค๋กœ์ง€ cli ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด ๊ด€๋ฆฌํ•ด์•ผํ•œ๋‹ค!)


ํ”„๋กœ์ ํŠธ ๊ณต์œ 

ํ˜„์žฌ ํ”„๋กœ์ ํŠธ๋Š” Git์˜ ์›๊ฒฉ ์ €์žฅ์†Œ์— ๋ฐ˜์˜ํ•ด์š” ํ˜‘์—…ํ•˜๋Š” ๋™๋ฃŒ์™€ ๊ณต์œ ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

ํ”„๋กœ์ ํŠธ์— ์ƒ์„ฑ๋œ pakage.json๊ณผ yarn.lock ํŒŒ์ผ๋„ ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๊ด€๋ฆฌํ•ด์•ผ ํ˜‘์—…ํ•˜๋Š” ๋™๋ฃŒ๋“ค๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์•ˆ์ •์ ์œผ๋กœ ์šด์˜ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ด์ง


์›๊ฒฉ ์ €์žฅ์†Œ์— ๊ณต์œ  ์‹œ, ๋ชจ๋“ˆ์ด ์„ค์น˜๋˜๋Š” node-_modules ํด๋”๋Š” ์ œ์™ธ์‹œ์ผœ์•ผ ํ•œ๋‹ค. ํด๋”์˜ ์šฉ๋Ÿ‰๋„ ํฌ๊ณ , ์–ด์ฐจํ”ผ yarn.lock ํŒŒ์ผ์„ ํ†ตํ•ด ๋™๊ธฐํ™” ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ git ์ €์žฅ์†Œ์—์„œ ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์—†์Œ

๋”ฐ๋ผ์„œ, ํ•ด๋‹น ํด๋”๋ฅผ .gitignore ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•ด git ๊ด€๋ฆฌ ๋Œ€์ƒ์—์„œ ์ œ์™ธ์‹œํ‚ค์ž

$ echo "node_modules/" > .gitignore


์ด์Šˆ ํ•ด๊ฒฐ ๊ด€๋ จ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ & ํ”„๋กœ์ ํŠธ push

์ด๋ฒˆ์—” ์ด์Šˆ ํ•ด๊ฒฐ๊ณผ ๊ด€๋ จ๋œ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ํ”„๋กœ์ ํŠธ๋ฅผ github์— ํ‘ธ์‹œํ•ด๋ณด์ž

$ git add .
$ git checkout -b issue/1
$ git commit -m 'Create project with Yarn'
$ git push -u origin issue/1

ํ‘ธ์‹œ๊ฐ€ ์™„๋ ค๋˜๋ฉด, GitHub ์ €์žฅ์†Œ์— pull request๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

pull request๋Š” ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ master ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•˜๊ธฐ ์œ„ํ•ด ํ˜‘์—…ํ•˜๋Š” ๋™๋ฃŒ๋“ค์—๊ฒŒ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ์š”์ฒญํ•˜๋Š” ์ž‘์—…์ž„

Pull requests ํƒญ์—์„œ New pull request ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด pull request๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค


pull request์‹œ ์ฃผ์˜ํ•  ์ 

๋ฆฌ๋ทฐ๋ฅผ ํ•˜๋Š” ์‚ฌ๋žŒ์—๊ฒŒ ์ถฉ๋ถ„ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•จ

์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ–ˆ์œผ๋ฉด, ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์žฌํ˜„ ์‹œ๋‚˜๋ฆฌ์˜ค์™€ ํ…Œ์ŠคํŠธ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Œ.

๊ฐœ๋ฐœ ํ™˜๊ฒฝ์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค๋ฉด ๋ณ€๊ฒฝ ๋‚ด์—ญ๋„ ๋ฐ˜๋“œ์‹œ ํฌํ•จํ•˜์ž


Jest๋กœ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ์„ค์ •

์‹ค์ œ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด, ํ™œ์šฉ๋˜๋Š” Javascript ๊ตฌํ˜„ ์ฝ”๋“œ๊ฐ€ ๋งŒ๋“ค์–ด์งˆ ๊ฒƒ์ด๊ณ  ์ด๋ฅผ ๊ฒ€์ฆํ•˜๋Š” ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์ด ํ•„์š”ํ•˜๊ฒŒ ๋œ๋‹ค.

Javascript ํ…Œ์ŠคํŠธ ๋„๊ตฌ๋กœ๋Š” jest๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.


GitHub์˜ REST API v3์„ ํ™œ์šฉํ•ด ํŠน์ • GitHub ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด๊ณ , ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ์„ค์ • ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž


ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ

๊ตฌํ˜„ ์ฝ”๋“œ ์ž‘์„ฑ ์ด์ „, ๊ตฌํ˜„ํ•˜๋ ค๋Š” ๊ธฐ๋Šฅ์˜ ์˜๋„๋ฅผ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ‘œํ˜„ํ•ด๋ณด์ž

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ €์žฅ ํด๋” : __test__

๊ตฌํ˜„ ์ฝ”๋“œ ์ €์žฅ ํด๋” : lib

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ : github.test.js


$ mkdir __tests__ lib
$ touch __tests__/github.test.js

github.test.js์— ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์ž

๋‚ด GitHub kim6394 ๊ณ„์ •์˜ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์™”๋Š”์ง€ ํ™•์ธํ•˜๋Š” ์ฝ”๋“œ๋‹ค.

const GitHub = require('../lib/github')

describe('Integration with GitHub API', () => {
    let github

    beforeAll ( () => {
        github = new GitHub({
            accessToken: process.env.ACCESS_TOKEN,
            baseURL: 'https://api.github.com',
        })
    })

    test('Get a user', async () => {
        const res = await github.getUser('kim6394')
        expect(res).toEqual (
            expect.objectContaining({
                login: 'kim6394',
            })
        )
    })
})

Jest ์„ค์น˜

yarn์—์„œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋Š” yarn test

๋จผ์ € ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•˜์ž

$ yarn add jest --dev

--dev ์†์„ฑ์€ ๋ญ”๊ฐ€์š”?

์„ค์น˜ํ•  ๋•Œ ์ด์ฒ˜๋Ÿผ ์ž‘์„ฑํ•˜๋ฉด, devDependencies ์†์„ฑ์— ํŒจํ‚ค์ง€๋ฅผ ์ถ”๊ฐ€์‹œํ‚จ๋‹ค. ์ด ์˜ต์…˜์œผ๋กœ ์„ค์น˜๋œ ํŒจํ‚ค์ง€๋Š”, ์•ฑ์ด ์‹คํ–‰๋˜๋Š” ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค.


ํ…Œ์ŠคํŠธ ๋ช…๋ น์„ ์œ„ํ•œ script ์†์„ฑ์„ pakage.json์— ์„ค์ •ํ•˜์ž

  "scripts": {
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "node-fetch": "^2.6.0"
  },
  "devDependencies": {
    "jest": "^24.8.0"
  }

๊ตฌํ˜„ ์ฝ”๋“œ ์ž‘์„ฑ

์•„์ง ๊ตฌํ˜„ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ํ…Œ์ŠคํŠธ ์‹คํ–‰์ด ๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค.

lib ํด๋”์— ๊ตฌํ˜„ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์ž

lib/github.js

const fetch = require('node-fetch')

class GitHub {
    constructor({ accessToken, baseURL }) {
        this.accessToken = accessToken
        this.baseURL = baseURL
    }

    async getUser(username) {
        if(!this.accessToken) {
            throw new Error('accessToken is required.')
        }

        return fetch(`${this.baseURL}/users/${username}`, {
            method: 'GET',
            headers: {
                Authorization: `token ${this.accessToken}`,
                'Content-Type' : 'application/json',
            },
        }).then(res => res.json())
    }
}

module.exports = GitHub

์ด์ œ GitHub ํ™ˆํŽ˜์ด์ง€์—์„œ access token์„ ์ƒ์„ฑํ•ด์„œ ํ…Œ์ŠคํŠธํ•ด๋ณด์ž

ํ† ํฐ์€ ์‚ฌ์šฉ์ž๋งˆ๋‹ค ๋‹ค๋ฅด๋ฏ€๋กœ ์ž์‹ ์ด ์ƒ์„ฑํ•œ ํ† ํฐ ๊ฐ’์œผ๋กœ ์ž…๋ ฅํ•œ๋‹ค

$ ACCESS_TOKEN=29ed3249e4aebc0d5cfc39e84a2081ad6b24a57c yarn test

์•„๋ž˜์™€ ๊ฐ™์ด ํ…Œ์ŠคํŠธ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™๋˜์–ด ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค!

yarn run v1.10.1
$ jest
 PASS  __tests__/github.test.js
  Integration with GitHub API
    โˆš Get a user (947ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.758s
Ran all test suites.
Done in 5.30s.


Travis CI๋ฅผ ํ™œ์šฉํ•œ ๋ฆฌ๋ทฐ ํ™˜๊ฒฝ ๊ฐœ์„ 


๋™๋ฃŒ์™€ ํ˜‘์—…ํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š” ๊ณผ์ •์€, pull request๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ณต์œ ํ•œ ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐ, ํ•จ๊ป˜ ๊ฐœ์„ ํ•˜๋Š” ๊ณผ์ •์ด๋ผ๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.

์ง€๊ธˆ๊นŒ์ง€ ์ง„ํ–‰ํ•œ ๊ณผ์ •์„ ํ™•์ธํ•œ ๋ฆฌ๋ทฐ์–ด๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‹ต์„ ๋ณด๋‚ด์™”๋‹ค.


README.md๋ฅผ ์ฐธ๊ณ ํ•ด ํ…Œ์ŠคํŠธ ๋ช…๋ น์„ ์‹คํ–‰ํ–ˆ์ง€๋งŒ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค..


๋ฌด์Šจ ๋ฌธ์ œ์ผ๊นŒ? ๋‚ด ๋กœ์ปฌ ํ™˜๊ฒฝ์—์„œ๋Š” ๋ถ„๋ช… ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ํ†ตํ•ด ํ…Œ์ŠคํŠธ ์„ฑ๊ณต์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ๋ฆฌ๋ทฐ์–ด๊ฐ€ ๋ณด๋‚ธ ๋ฌธ์ œ๋Š”, ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ํ…Œ์ŠคํŠธ ์‹คํŒจ๋กœ ์ธํ•œ ๋ฌธ์ œ๋‹ค.

์ด์ฒ˜๋Ÿผ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์— ์ •์˜๋œ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์ผ์€ ๊ฐœ๋ฐœ๊ณผ์ •์—์„œ ๋ฐ˜๋ณต๋˜๋Š” ์ž‘์—…์ด๋‹ค. ๋”ฐ๋ผ์„œ ๋ฆฌ๋ทฐ์–ด๊ฐ€ ํ…Œ์ŠคํŠธ๋ฅผ ๋งค๋ฒˆ ์‹คํ–‰ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฑด ๋งค์šฐ ๋น„ํšจ์œจ์ ์ด๋‹ค.

CI ๋„๊ตฌ๊ฐ€ ์ž๋™์œผ๋กœ ์‹คํ–‰ํ•˜๋„๋ก ํ”„๋กœ์ ํŠธ ๋ฆฌ๋ทฐ ๋ฐฉ๋ฒ•์„ ๊ฐœ์„ ์‹œ์ผœ๋ณด์ž


Travis CI๋กœ ํ…Œ์ŠคํŠธ ์ž๋™ํ™”

์ €์žฅ์†Œ์˜ Settings ํƒญ์—์„œ Branches๋ฅผ ํด๋ฆญํ•œ ํ›„, Branch protection rules์—์„œ CI ์—ฐ๋™๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด๋ณด์ž

(CI ๋„๊ตฌ ๋นŒ๋“œ ํ”„๋กœ์„ธ์Šค์— ์ •์˜ํ•œ ์ž‘์—…์ด ์„ฑ๊ณตํ•ด์•ผ๋งŒ master ๋ธŒ๋žœ์น˜์— ์†Œ์Šค์ฝ”๋“œ๊ฐ€ ๋ณ‘ํ•ฉ๋˜๋„๋ก ์ œ์•ฝ ์กฐ๊ฑด์„ ์ฃผ๋Š” ๊ฒƒ)


๋Œ€ํ‘œ์ ์ธ CI ๋„๊ตฌ๋Š” Jenkins์ด์ง€๋งŒ, CI ์„œ๋ฒ„ ๊ตฌ์ถ• ์šด์˜์— ๋น„์šฉ์ด ๋“ ๋‹ค.


Travis CI๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์ž‘์—…์„ ์œ„์ž„ํ•œ๋‹ค

  • ESLint๋ฅผ ํ†ตํ•œ ์ฝ”๋“œ ์ปจ๋ฒค์…˜ ๊ฒ€์ฆ
  • Jest๋ฅผ ํ†ตํ•œ ํ…Œ์ŠคํŠธ ์ž๋™ํ™”

Travis CI์˜ ์—ฐ๋™๊ณผ ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด, pull request๋ฅผ ์š”์ฒญํ•œ ์†Œ์Šค์ฝ”๋“œ๊ฐ€ Travis CI๋ฅผ ๊ฑฐ์น˜๋„๋ก GitHub ์ €์žฅ์†Œ์˜ Branch protection rules ํ•ญ๋ชฉ์„ ์„ค์ •ํ•œ๋‹ค.

์ด๋ฅผ ์„ค์ •ํ•ด๋‘๋ฉด, ์ž‘์„ฑํ•ด๋‘” ๊ตฌํ˜„ ์ฝ”๋“œ์™€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ pull request๋ฅผ ์š”์ฒญํ–ˆ์„ ๋•Œ Travis CI ์„œ๋ฒ„์—์„œ ์ž๋™์œผ๋กœ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.


GitHub-Travis CI ์—ฐ๋™

https://travis-ci.org/์—์„œ GitHub Login

https://travis-ci.org/account/repositories์—์„œ ์—ฐ๊ฒฐํ•  repository ํ—ˆ์šฉ

ํ”„๋กœ์ ํŠธ์— .travis.yml ์„ค์ • ํŒŒ์ผ ์ถ”๊ฐ€


.travis.yml

---
language: node_js
node_js:
  - 10.15.0
cache:
  yarn: true
  directories:
  - node_modules

env:
  global:
    - PATH=$HOME/.yarn/bin:$PATH

services:
  - mongodb

before_install:
  - curl -o- -L https://yarnpkg.com/install.sh | bash

script:
 - yarn install
 - yarn test

๋‹ค์‹œ ๋Œ์•„์™€์„œ, ๋ฆฌ๋ทฐ์–ด๊ฐ€ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํŒจํ•œ ์ด์œ ๋Š” access token ๊ฐ’์ด ์ „๋‹ฌ๋˜์ง€ ๋ชปํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„  Git ์ €์žฅ์†Œ์—์„œ ์„ค์ • ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ , ๊ฐ’์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์ฆํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

(๋ณด์•ˆ ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ๋•Œ๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ• ๊ฐ•๊ตฌ)


dotenv๊ณผ joi ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ฉด, .env ํ•  ์ผ์— ์›ํ•˜๋Š” ๊ฐ’์„ ๋“ฑ๋กํ•˜๊ณ  ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ”„๋กœ์ ํŠธ์— .env ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ , access token ๊ฐ’์„ ๋“ฑ๋กํ•ด๋‘์ž


์ด์ œ yarn์œผ๋กœ ๋‘ ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•œ๋‹ค.

$ yarn add dotenv joi
$ git add .
$ git commit -m 'Integration with dotenv and joi to manage config properties'
$ git push

์ด์ œ Travis CI๋กœ ์ž๋™ ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.



Node.js ๋ฒ„์ „ ์œ ์ง€์‹œํ‚ค๊ธฐ


๊ฐœ๋ฐœ์ž๋“ค๊ฐ„์˜ Node.js ๋ฒ„์ „์ด ๋‹ฌ๋ผ์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„œ๋น„์Šค๋ฅผ ์•ˆ์ •์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐœ๋ฐœ์ž์˜ ๋กœ์ปฌ ์‹œ์Šคํ…œ, CI ์„œ๋ฒ„, ๋นŒ๋“œ ์„œ๋ฒ„์˜ Node.js ๋ฒ„์ „์„ ์ผ๊ด€์ ์œผ๋กœ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค.


package.json์—์„œ engines ์†์„ฑ, nvm์„ ํ™œ์šฉํ•ด ๋ฒ„์ „์„ ์ผ๊ด€๋˜๊ฒŒ ์œ ์ง€ํ•ด๋ณด์ž

"engines": {
    "node": ">=10.15.3",
 },

.nvmrc ํŒŒ์ผ ์ถ”๊ฐ€ ํ›„, nvm use ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด engines ์†์„ฑ์— ์„ค์ •ํ•œ Node.js์˜ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ๋‹ค.


$ echo "10.15.3" > .nvmrc
$ git add .
$ nvm use
Found '/Users/user/github/awesome-javascript/.nvmrc' with version <10.15.3>  
Now using node v10.15.3 (npm v6.4.1)  
...
$ git commit -m 'Add .nvmrc to maintain the same Node.js LTS version'



์ง€๊ธˆ๊นŒ์ง€ ์•Œ์•„๋ณธ ์ 

  • Git๊ณผ GitHub์„ ํ™œ์šฉํ•ด ํ˜‘์—… ๊ณต๊ฐ„์„ ๊ตฌ์„ฑ
  • Node.js ๊ธฐ๋ฐ˜ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ๊ณผ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ์„ค์ •
  • ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ GitHub์— ๊ณต์œ ํ•˜๊ณ  ๋ฆฌ๋ทฐํ•˜๋ฉด์„œ ๋ฐœ์ƒ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ์‹œ์ผœ๋‚˜๊ฐ

์ง€์†์ ์ธ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ์ž๋™ํ™”๋ฅผ ์‹œํ‚ค์ž. ์ด์— ์‚ฌ์šฉํ•˜๊ธฐ ์ข‹์€ ๊ฒƒ๋“ค

  • ESLint๋กœ ์ฝ”๋“œ ์ปจ๋ฒค์…˜ ๊ฒ€์ฆ
  • Jest๋กœ ํ…Œ์ŠคํŠธ ์ž๋™ํ™”
  • Codecov๋กœ ์ฝ”๋“œ ์ปค๋ฒ„๋ฆฌ์ง€ ์ ๊ฒ€
  • GitHub์˜ webhook api๋กœ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์š”์ฒญ

์ž๋™ํ™”๋ฅผ ์‹œ์ผœ๋†“์œผ๋ฉด, ๊ฐœ๋ฐœ์ž๋“ค์€ ์ฝ”๋“œ ์˜๋„๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” commit message, commit range๋งŒ ์‹ ๊ฒฝ ์“ฐ๋ฉด ๋œ๋‹ค.


ํ˜‘์—…ํ•˜๋ฉฐ ๊ฐœ๋ฐœํ•˜๋Š” ๊ณผ์ •์—๋Š” ์ฝ”๋“œ ์ž‘์„ฑ ํ›„ pull request๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ณ‘ํ•ฉ๊นŒ์ง€ ๋งŽ์€ ๊ฒ€์ฆ์ด ํ•„์š”ํ•˜๋‹ค.

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ์ด ๊ณผ์ •์—์„œ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ํ™•๋ฅ ์„ ์ค„์—ฌ์ฃผ๋ฉฐ, ๊ตฌํ˜„ ์ฝ”๋“œ ์˜๋„๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

๋˜ํ•œ ๋ฆฌ๋ทฐ ์‹œ, ์ฝ”๋“œ ์ปจ๋ฒค์…˜ ๊ฒ€์ฆ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์˜ ๋ฐœ์ƒ ๋ฌธ์ œ๋„ ๊ณ ๋ฏผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.



[์ฐธ๊ณ  ์‚ฌํ•ญ]