-
포스트맨으로 Git Repository 파일 수정하기웹개발/깃허브 2019. 4. 15. 15:27
참고자료
https://stackoverflow.com/questions/48745796/github-api-v3-update-file-not-working-404
https://stackoverflow.com/questions/20207594/how-to-find-a-github-file-s-sha-blob
깃허브 API 메뉴얼 : https://developer.github.com/v3/repos/contents/#update-a-file
1 API ENDPOINT
위 메뉴얼에 설명이 되있긴하지만 메뉴얼만으로는 무슨말인지ㅠ 구체적으로 어떻게 해야할지 모르겠음.
그래서 조사결과
깃 레파지토리 파일을 수정하기 위한 엔드포인트 :
https://api.github.com/repos/유저이름/레파지토리이름/contents/파일이름
회색 글씨는 그대로 쓰면되고 파란글씨에는 맞는 값을 넣으면된다.
보내는 방식은 PUT로 한다
2 쓰기권한 있는 OAuth 인증키 생성
일단 Headers에 인증키를 넣어야하는데 깃허브 계정페이지에서 얻을 수 있다.
프로필 사진을 눌러서 Settings > Developer settings > Personal access tokens 메뉴를 클릭한다.
이미 기본토큰들이 있겠지만 새로운 토큰을 만들어야한다. 쓰기 권한있는 토큰이 필요하기 때문.
필요한 권한들을 클릭해주고 생성된 키 값을 복사한다.
3 Headers 작성
그리고 Headers에 다음과 같이 Key는 Authorization으로 value는 token이라 쓰고 한칸 띄우고 복사한 토큰값을 붙여넣는다.
4 Body 작성
바디에는 다음과 같이 JSON형식으로 보낸다.
message, content, sha값은 필수값이므로 누락되면 에러메세지를 리턴한다.
message는 커밋 메세지를 쓰면되고 content는 Base64 형식으로 인코딩된 값을 넣어야한다.
4-1 content 값 작성
위 링크에서 변환하여 붙여넣으면 된다.
4-2 sha값 알아내기
sha값은 지금 PUT할 url을 GET방식으로 요청하면 리턴되는 json에 sha값이 있다.
일단 GET방식으로 던져서 sha값을 복사하여 PUT으로 던질 양식을 완성한다.
5 수정요청 보내기
드디어 Headers와 Body가 올바르게 완성되었으므로 Send를 클릭하면
성공리턴 제이슨이 온다.
그리고 주의할 점은 content 값으로 내용이 완전 대체 된다는 점이다.
content 값으로 기존 파일에 추가가 아니라 덮어쓰기된다.
'웹개발 > 깃허브' 카테고리의 다른 글
윈도우에서 cURL 써서 Git API 사용하기 (0) 2019.04.16 Config Server 깃 저장소 어플리케이션마다 디렉토리 나누기 (0) 2019.04.15 [에러]Config Client 실행시 Config Server Git Repository를 찾지 못함/ Working tree is not clean 에러 메세지 (0) 2019.04.15 댓글