๋์ด์ค๊ธฐ ์์ฒญ์ ๊ฒฝ์ฐ GitHub๋ ๋์ด์ค๊ธฐ ์์ฒญ์ ์ฃผ์ ์ ์ฒด, ๋์ด์ค๊ธฐ ์์ฒญ ๋ด์ ํน์ ์ค์ ๋ํ ์ฃผ์, ๋์ด์ค๊ธฐ ์์ฒญ ๋ด์ ํน์ ์ปค๋ฐ์ ๋ํ ์ฃผ์์ ์ธ ๊ฐ์ง ์ข ๋ฅ์ ์ฃผ์ ๋ณด๊ธฐ๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ด๋ฌํ ๊ฐ ์ ํ์ ์ฃผ์์ GitHub API์ ๋ค๋ฅธ ๋ถ๋ถ์ ๊ฑฐ์นฉ๋๋ค. ์ด ๊ฐ์ด๋์์๋ ๊ฐ ํญ๋ชฉ์ ์ก์ธ์คํ๊ณ ์กฐ์ํ๋ ๋ฐฉ๋ฒ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋ชจ๋ ์์ ์์๋ โoctocatโ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ง๋ ์ด ์ํ ๋์ด์ค๊ธฐ ์์ฒญ์ ์ฌ์ฉํฉ๋๋ค. ์ธ์ ๋์ฒ๋ผ ์ํ์ ํ๋ซํผ ์ํ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ฐพ์ ์ ์์ต๋๋ค.
๋์ด์ค๊ธฐ ์์ฒญ ์ฃผ์
๋์ด์ค๊ธฐ ์์ฒญ์ ๋ํ ์ค๋ช ์ ์ก์ธ์คํ๋ ค๋ฉด ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ด์๋ฅผ ๊ด๋ฆฌํฉ๋๋ค. ์ฒ์์๋ ์ง๊ด์ ์ด์ง ์์ ๊ฒ์ฒ๋ผ ๋ณด์ผ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋์ด์ค๊ธฐ ์์ฒญ์ด ์ฝ๋์ ์ด์์ผ ๋ฟ์ด๋ผ๋ ๊ฒ์ ์ดํดํ๋ฉด ์ด๋ฌํ ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋์ด์ค๊ธฐ ์์ฒญ์ ๋ํ ์ฃผ์์ ๋ง๋๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ ๋๋ค.
Octokit.rb๋ฅผ ์ฌ์ฉํ์ฌ Ruby ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ค์ด ๋์ด์ค๊ธฐ ์์ฒญ ์ฃผ์์ ํ์นํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค. personal access token์(๋ฅผ) ๋ง๋ค ์๋ ์์ต๋๋ค.
๋ค์ ์ฝ๋๋ Octokit.rb๋ฅผ ์ฌ์ฉํ์ฌ ๋์ด์ค๊ธฐ ์์ฒญ์์ ์ฃผ์์ ์ก์ธ์คํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
require 'octokit'
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!!
# Instead, set and test environment variables, like below
client = Octokit::Client.new :access_token => ENV['MY_PERSONAL_TOKEN']
client.issue_comments("octocat/Spoon-Knife", 1176).each do |comment|
username = comment[:user][:login]
post_date = comment[:created_at]
content = comment[:body]
puts "#{username} made a comment on #{post_date}. It says:\n'#{content}'\n"
end
์ฌ๊ธฐ์๋ ํนํ API๋ฅผ ํธ์ถํ์ฌ ์ฃผ์(issue_comments
)์ ๊ฐ์ ธ์ค๊ณ , ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ด๋ฆ(octocat/Spoon-Knife
) ๋ฐ ๊ด์ฌ ์๋ ๋์ด์ค๊ธฐ ์์ฒญ ID(1176
)๋ฅผ ๋ชจ๋ ์ ๊ณตํฉ๋๋ค. ๊ทธ ํ์๋ ๊ฐ ์ฃผ์์ ๋ํ ์ ๋ณด๋ฅผ ํ์นํ๊ธฐ ์ํด ์ฃผ์์ ๋ฐ๋ณตํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
์ค์ ๋์ด์ค๊ธฐ ์์ฒญ ์ฃผ์
๋น๊ต ๋ณด๊ธฐ ๋ด์์ ๋์ด์ค๊ธฐ ์์ฒญ ๋ด์์ ์ด๋ฃจ์ด์ง ๋จ์ผ ๋ณ๊ฒฝ์ ํน์ ์ธก๋ฉด์ ๋ํ ํ ๋ก ์ ์์ํ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ฃผ์์ ๋ณ๊ฒฝ๋ ํ์ผ ๋ด์ ๊ฐ๋ณ ์ค์์ ๋ฐ์ํฉ๋๋ค. ์ด ํ ๋ก ์ ์๋ํฌ์ธํธ URL์ ๋์ด์ค๊ธฐ ์์ฒญ ๊ฒํ ๋ฅผ ๊ด๋ฆฌํ๋ ์๋ํฌ์ธํธ์์ ๊ฐ์ ธ์ต๋๋ค.
๋ค์ ์ฝ๋๋ ๋จ์ผ ๋์ด์ค๊ธฐ ์์ฒญ ๋ฒํธ๊ฐ ์ง์ ๋ ํ์ผ์ ๋ํ ๋ชจ๋ ๋์ด์ค๊ธฐ ์์ฒญ ์ฃผ์์ ํ์นํฉ๋๋ค.
require 'octokit'
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!!
# Instead, set and test environment variables, like below
client = Octokit::Client.new :access_token => ENV['MY_PERSONAL_TOKEN']
client.pull_request_comments("octocat/Spoon-Knife", 1176).each do |comment|
username = comment[:user][:login]
post_date = comment[:created_at]
content = comment[:body]
path = comment[:path]
position = comment[:position]
puts "#{username} made a comment on #{post_date} for the file called #{path}, on line #{position}. It says:\n'#{content}'\n"
end
์์ ์์ ์ ๋งค์ฐ ๋น์ทํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. ์ด ๋ณด๊ธฐ์ ๋์ด์ค๊ธฐ ์์ฒญ ์ฃผ์์ ์ฐจ์ด์ ์ ๋ํ์ ์ด์ ์ ๋๋ค. ๋์ด์ค๊ธฐ ์์ฒญ์ ๋ํ ์ฃผ์์ ์ฝ๋์ ์ ๋ฐ์ ์ธ ๋ฐฉํฅ์ ๋ํ ํ ๋ก ๋๋ ์์ด๋์ด๋ฅผ ์ํด ์์ฝ๋์ด์ผ ํฉ๋๋ค. ๋์ด์ค๊ธฐ ์์ฒญ ๊ฒํ ์ ์ผ๋ถ๋ก ๋ง๋ ์ฃผ์์ ํ์ผ ๋ด์์ ํน์ ๋ณ๊ฒฝ์ด ๊ตฌํ๋ ๋ฐฉ์์ ๊ตฌ์ฒด์ ์ผ๋ก ๋ค๋ฃจ์ด์ผ ํฉ๋๋ค.
์ปค๋ฐ ์ฃผ์
๋ง์ง๋ง ์ ํ์ ์ฃผ์์ ๊ฐ๋ณ ์ปค๋ฐ์์ ํนํ ๋ฐ์ํฉ๋๋ค. ์ด๋ฌํ ์ด์ ๋ก ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ปค๋ฐ ์ค๋ช ์ ๊ด๋ฆฌํฉ๋๋ค.
์ปค๋ฐ์ ๋ํ ์ฃผ์์ ๊ฒ์ํ๋ ค๋ฉด ์ปค๋ฐ์ SHA1์ ์ฌ์ฉํฉ๋๋ค. ์ฆ, ๋์ด์ค๊ธฐ ์์ฒญ๊ณผ ๊ด๋ จ๋ ์๋ณ์๋ ์ฌ์ฉํ์ง ์์ต๋๋ค. ์๋ฅผ ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
require 'octokit'
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!!
# Instead, set and test environment variables, like below
client = Octokit::Client.new :access_token => ENV['MY_PERSONAL_TOKEN']
client.commit_comments("octocat/Spoon-Knife", "cbc28e7c8caee26febc8c013b0adfb97a4edd96e").each do |comment|
username = comment[:user][:login]
post_date = comment[:created_at]
content = comment[:body]
puts "#{username} made a comment on #{post_date}. It says:\n'#{content}'\n"
end
์ด API ํธ์ถ์ ๋จ์ผ ์ค ์ฃผ์๊ณผ ์ ์ฒด ์ปค๋ฐ์ ๋ํ ์ฃผ์์ ๊ฒ์ํฉ๋๋ค.