Skip to content

Commit 8389a24

Browse files
committed
Invoke is a thing I guess.
1 parent b566039 commit 8389a24

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tasks.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
3+
import requests
4+
5+
from invoke import task
6+
7+
8+
API_URL = 'https://ci.appveyor.com/api'
9+
TOKEN = os.environ["APPVEYOR_API_TOKEN"]
10+
ACCOUNT_NAME = "lukasa"
11+
PROJECT_NAME = "certitude"
12+
BASE_URL = "https://ci.appveyor.com/api"
13+
14+
15+
@task
16+
def download_artifacts(build_id):
17+
s = requests.Session()
18+
s.headers = {
19+
"Authorization": "Bearer {}".format(TOKEN)
20+
}
21+
22+
# Get project build details.
23+
print "Obtaining artifacts for {}".format(PROJECT_NAME)
24+
build_details_url = BASE_URL + "/projects/{}/{}/build/{}".format(
25+
ACCOUNT_NAME, PROJECT_NAME, build_id
26+
)
27+
r = s.get(build_details_url, stream=True)
28+
r.raise_for_status()
29+
30+
for job in r.json()[u'build'][u'jobs']:
31+
# Get the artifact list because we don't know what the filename is.
32+
job_id = job[u'jobId']
33+
artifacts_url = BASE_URL + "/buildjobs/{}/artifacts/".format(job_id)
34+
35+
print "Artifacts for {}".format(job_id)
36+
r = s.get(artifacts_url, stream=True)
37+
r.raise_for_status()
38+
39+
artifact_name = r.json()[0][u'fileName']
40+
artifact = BASE_URL + "/buildjobs/{}/artifacts/{}".format(
41+
job_id, artifact_name
42+
)
43+
44+
print "Downloading {} to {}".format(artifact, artifact_name)
45+
r = s.get(artifact, stream=True)
46+
r.raise_for_status()
47+
48+
with open("{}".format(artifact_name), 'wb') as f:
49+
for chunk in r.iter_content(4096):
50+
f.write(chunk)

0 commit comments

Comments
 (0)