|
16 | 16 | #
|
17 | 17 |
|
18 | 18 | import argparse
|
19 |
| -import hashlib |
20 | 19 | import json
|
21 | 20 | import os
|
22 | 21 | # Run `pip3 install requests` if not installed yet
|
23 | 22 | import requests
|
| 23 | +# Run `pip3 install re` if not installed yet |
| 24 | +import re |
24 | 25 |
|
25 | 26 | # This script downloads artifacts from GitHub.
|
26 | 27 | # Ref: https://docs.github.com/en/rest/actions/artifacts#get-an-artifact
|
|
65 | 66 | print(args)
|
66 | 67 |
|
67 | 68 | # Split the artifact URL to get information
|
68 |
| -# Ex: https://github.com/element-hq/element-android/suites/9293388174/artifacts/435942121 |
| 69 | +# Ex: https://github.com/element-hq/element-android/actions/runs/7460386865/artifacts/1156548729 |
69 | 70 | artifactUrl = args.artifactUrl
|
70 |
| -if not artifactUrl.startswith('https://github.com/'): |
71 |
| - print("❌ Invalid parameter --artifactUrl %s. Must start with 'https://github.com/'" % artifactUrl) |
72 |
| - exit(1) |
73 |
| -if "/artifacts/" not in artifactUrl: |
74 |
| - print("❌ Invalid parameter --artifactUrl %s. Must contain '/artifacts/'" % artifactUrl) |
75 |
| - exit(1) |
76 |
| -artifactItems = artifactUrl.split("/") |
77 |
| -if len(artifactItems) != 9: |
78 |
| - print("❌ Invalid parameter --artifactUrl %s. Please check the format." % (artifactUrl)) |
| 71 | + |
| 72 | +url_regex = r"https://github.com/(.+?)/(.+?)/actions/runs/.+?/artifacts/(.+)" |
| 73 | +result = re.search(url_regex, artifactUrl) |
| 74 | + |
| 75 | +if result is None: |
| 76 | + print( |
| 77 | + "❌ Invalid parameter --artifactUrl '%s'. Please check the format.\nIt should be something like: %s" % |
| 78 | + (artifactUrl, 'https://github.com/element-hq/element-android/actions/runs/7460386865/artifacts/1156548729') |
| 79 | + ) |
79 | 80 | exit(1)
|
80 | 81 |
|
81 |
| -gitHubRepoOwner = artifactItems[3] |
82 |
| -gitHubRepo = artifactItems[4] |
83 |
| -artifactId = artifactItems[8] |
| 82 | +(gitHubRepoOwner, gitHubRepo, artifactId) = result.groups() |
84 | 83 |
|
85 | 84 | if args.verbose:
|
86 | 85 | print("gitHubRepoOwner: %s, gitHubRepo: %s, artifactId: %s" % (gitHubRepoOwner, gitHubRepo, artifactId))
|
|
0 commit comments