명령 줄을 사용하여 비공개 github 리포지토리에서 단일 원시 파일을 다운로드하려면 어떻게해야합니까?
CI 서버에서 여러 작업간에 공유 할 수 있도록 Github에서 유지 관리하는 구성 파일을 가져오고 싶습니다. 컬을 통해이 파일을 얻으려고하는데 이러한 접근 방식은 모두 실패합니다 (404가 표시됨).
# As advised by the oAuth docs
curl -H 'Authorization: token the_token' -L -o setup.sh https://raw.github.com/org/repo/file
# The url of the raw file after clicking to view it
curl -L https://raw.github.com/org/repo/file?login=username&token=the_token
이전 답변이 작동하지 않거나 더 이상 작동하지 않습니다.
V3 API를 사용하여 다음과 같은 원시 파일을 가져올 수 있습니다 (OAuth 토큰이 필요함).
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path
이 모든 것이 한 줄에 있어야합니다. 이 -O
옵션은 현재 디렉토리에 파일을 저장합니다. -o filename
다른 파일 이름을 지정하는 데 사용할 수 있습니다 .
OAuth 토큰을 얻으려면 https://help.github.com/articles/creating-an-access-token-for-command-line-use 의 지침을 따르십시오.
나는 이것을 요점으로도 작성했습니다 : https://gist.github.com/madrobby/9476733
편집 : 솔루션에 대한 API 참조는 다음과 같습니다.
- https://developer.github.com/v3/#authentication
- https://developer.github.com/v3/media/#request-specific-version
- https://developer.github.com/v3/repos/contents/#get-contents
또는 github "개인 액세스 토큰"( https://github.com/settings/tokens )을 사용할 수 있습니다 .
TOKEN=...
curl -s https://$TOKEN@raw.githubusercontent.com/<user or organization>/<repo name>/<branch>/<path to file>/<file_name>
예:
$ curl -s https://1bacnotmyrealtoken123beefbea@raw.githubusercontent.com/concourse/concourse/master/README.md
....
나는 이것이 오래된 질문이라는 것을 알고 있지만 위에서 제안한 해결책 중 어느 것도 나를 위해 일하지 않았습니다. 그 이후로 API가 변경되었을 수 있습니다.
이것은 작동했습니다.
curl -H 'Authorization: token [insert your token here]' -o output.txt https://raw.githubusercontent.com/[organization]/[repo]/[branch]/[path to file]
또는 토큰이없는 경우 :
curl --user [your_user] 'https://raw.github.com/path/to/file.config' > file.config
앰퍼샌드를 피하기 위해 URL을 따옴표로 묶는 것이 필요하다는 것을 깨달을 때까지 몇 분 동안이 문제를 해결했습니다.
curl "https://raw.github.com/org/repo/file?login=username&token=the_token"
그것은 내 개인 저장소에서 나를 위해 일했습니다.
URL이 Amazon S3로 리디렉션 될 때 인증 오류가 발생했습니다.
하나의 인증 메커니즘 만 허용됩니다.
X-Amz-Algorithm
검색어 매개 변수 만 ...
Authorization: token X
헤더에서 ?access_token=<token>
쿼리 매개 변수 로 변경하면 저에게 효과적이었습니다.
허용되는 답변에 추가하면 Github Enterprise URL을 사용하는 경우 약간 다릅니다.
curl -H 'Authorization: token [your token]' \
-H 'Accept: application/vnd.github.v3.raw' \
-L https://[your domain]/api/v3/repos/[owner]/[repo-name]/contents/[path of file]
우리는 비공개 GitHub 저장소에서 파일을 꽤 자주 다운로드해야했고 해키 셸 스크립트가 제대로 처리하지 못했기 때문에 소스 파일을 쉽게 다운로드하고 자산을 배포 할 수있는 오픈 소스 크로스 플랫폼 도구 인 fetch 를 만들었습니다 . git 태그, 커밋 또는 공개 및 비공개 GitHub 저장소의 브랜치.
예를 들어 비공개 GitHub 저장소 baz
버전 에서로 파일을 다운로드 하려면 다음을 수행합니다.0.1.3
/tmp
GITHUB_OAUTH_TOKEN="your token"
fetch --repo="https://github.com/foo/bar" --tag="0.1.3" --source-path="/baz" /tmp
- 브라우저에서 github 저장소를 엽니 다. 파일을 클릭합니다.
- 브라우저에서 개발자 도구 열기 : 네트워크 탭 선택
- 브라우저 github에서 : 다운로드 버튼 클릭
- 팝업 닫기
- 브라우저 개발 도구에서 :
file_name?token=ABAHQCAT6KG...
복사 선택-> 링크 주소 복사
URL 형식 :
https://raw.githubusercontent.com/<USERNAME>/<PATH>/<FILENAME>?token=ABAHQCAT6KGHYHMG2SLCDT243PH4I
터미널에서 :
wget -O myFilename https://raw.githubusercontent.com/<USERNAME>/<PATH>/<FILENAME>?token=ABAHQCAT6KGHYHMG2SLCDT243PH4I
링크는 제한된 시간 동안 만 유효하거나 토큰을 생성 할 수 있습니다 : GitHub 기사
아래는 잘 작동합니다. 브랜치 이름 앞의 "원시"(이 경우 마스터).
curl -L -O https://github.com/your/repo/raw/master/fetch_file.sh
원시 링크로이를 수행 할 수 있습니다.
curl -O https://raw.githubusercontent.com/owner/repo/branchname/path/to/file
'IT TIP' 카테고리의 다른 글
node.js로 데스크톱 애플리케이션을 만들 수 있습니까? (0) | 2020.12.12 |
---|---|
Amazon S3에 일괄 업로드를 수행 할 수 있습니까? (0) | 2020.12.12 |
na.rm이있는 dplyr summarise_each (0) | 2020.12.11 |
Webstorm은 node.js로 매우 느려집니다. (0) | 2020.12.11 |
오류 aws ecs list-container-instances 명령을 실행할 때 지역을 지정해야합니다. (0) | 2020.12.11 |