File size: 1,195 Bytes
11ad855
 
 
 
 
 
 
fd053a1
11ad855
 
 
2734782
 
 
 
7822dce
11ad855
 
 
 
 
 
 
 
 
 
2734782
11ad855
 
 
3568671
3e49a42
11ad855
2734782
11ad855
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import argparse
import requests

def getArtifactUrl(runUrl):
    artifactUrl = None
    r = requests.get(runUrl)
    if r.status_code == 200:
        print(r.json()['artifacts'][0])
        artifactUrl = r.json()['artifacts'][0]["archive_download_url"]
    return artifactUrl

def getArtifact(artifactUrl, gh_tokenfile, outputfile):
    gh_token = None
    with open(gh_tokenfile, 'r') as f:
        gh_token = f.read()
    headers = {'Authorization': f'token {gh_token}'}
    r = requests.get(artifactUrl, headers=headers)
    if r.status_code == 200:
        with open(outputfile, mode="wb") as file:
            file.write(r.content)
    else:
        print(r.status_code)

def main():
    parser = argparse.ArgumentParser(description='Download artifact from github')
    parser.add_argument('url', help='url for the artifact building run')
    parser.add_argument('gh_tokenfile', help='authentication token')
    parser.add_argument('outputfile', help='where to store downloaded file')

    args = parser.parse_args()

    artifact_url = getArtifactUrl(args.url)
    print(artifact_url)
    getArtifact(artifact_url, args.gh_tokenfile, args.outputfile)

if __name__ == '__main__':
    main()