성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# - REST API 대신 github 클라이언트 라이브러리를 통해 프로그래밍으로 접근</h1> <p> 예를 들어, 예전에 github README에 badge를 달아본 적이 있는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 애저듣보잡 - Github Workflow/Actions 소개 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12541#badge'>https://www.sysnet.pe.kr/2/0/12541#badge</a> </pre> <br /> 이와 함께 <a target='tab' href='https://shields.io/'>Shields IO</a>를 사용하면 아래와 같이 더욱 다양한 배지를 달 수 있습니다.<br /> <br /> [그림: <a target='tab' href='https://github.com/stjeong/Utilities'>https://github.com/stjeong/Utilities</a> README의 배지]<br /> <img alt='github_badge_1.png' src='/SysWebRes/bbs/github_badge_1.png' /><br /> <br /> 그런데 위에서 보면 "tag"의 값으로 "v1.1.3"을 가져오는데, 예상할 수 있듯이 이런 것들은 github 측에서 제공하는 REST API를 통해 알아낼 수 있는 값입니다. 실제로 간단하게 curl을 이용해 다음과 같이 가장 최근에 릴리스된 태그 버전을 구할 수 있는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>curl --silent https://api.github.com/repos/stjeong/Utilities/releases/latest | findstr tag_name</span> "tag_name": "v1.1.3", </pre> <br /> 그리고 당연히 누군가는 이에 대한 C# 전용 클라이언트를 만들어 두었을 것입니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > octokit/octokit.net ; <a target='tab' href='https://github.com/octokit/octokit.net'>https://github.com/octokit/octokit.net</a> </pre> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // 최소 .NET 4.6, .NET Standard 2.0 Install-Package Octokit </pre> <br /> 게다가 도움말도 잘 되어 있어서,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Octokit.net ; <a target='tab' href='https://octokitnet.readthedocs.io/en/latest/'>https://octokitnet.readthedocs.io/en/latest/</a> </pre> <br /> 다음과 같이 특정 사용자의 repo에 대한 최신 태그 이름을 가져오도록 간단하게 코딩할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using Octokit; using System; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { // https://octokitnet.readthedocs.io/en/latest/getting-started/ <span style='color: blue; font-weight: bold'>GitHubClient github = new GitHubClient(new ProductHeaderValue("octokit-client"));</span> // https://octokitnet.readthedocs.io/en/latest/releases/ Release latest = await <span style='color: blue; font-weight: bold'>github.Repository.Release.GetLatest</span>("stjeong", "Utilities"); Console.WriteLine( "The latest release is tagged at {0} and is named {1}", <span style='color: blue; font-weight: bold'>latest.TagName</span>, latest.Name); } } </pre> <br /> <hr style='width: 50%' /><br /> <a name='pat'></a> <br /> 참고로, github API 사용에는, 인증을 요구하는 것과 그렇지 않은 것이 있습니다. 위에서 했던 tagname을 가져오는 것은 인증이 필요없었지만 해당 repo에 대해 권한이 요구되는 것들은 반드시 사용 전에 Access token을 설정해야 정상적인 사용이 가능합니다. 이를 위해 우선 PAT를 구하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Creating a personal access token ; <a target='tab' href='https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token'>https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token</a> </pre> <br /> 아래의 예제에서 보여주듯이,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Docs » Samples » Exploring Pull Requests ; <a target='tab' href='https://octokitnet.readthedocs.io/en/latest/demos/exploring-pull-requests/'>https://octokitnet.readthedocs.io/en/latest/demos/exploring-pull-requests/</a> </pre> <br /> InMemoryCredentialStore에 PAT 값을 담아 GitHubClient를 초기화하면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <span style='color: blue; font-weight: bold'>InMemoryCredentialStore credentials</span> = new InMemoryCredentialStore(new Credentials(<span style='color: blue; font-weight: bold'>"...your-token-here..."</span>)); GitHubClient client = new GitHubClient(new ProductHeaderValue("octokit-client"), <span style='color: blue; font-weight: bold'>credentials</span>); </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1943
(왼쪽의 숫자를 입력해야 합니다.)