Skip to content

Commit

Permalink
Merge pull request #10 from donhui/scanning
Browse files Browse the repository at this point in the history
add api: scan_build
  • Loading branch information
donhui committed Feb 28, 2023
2 parents 2530393 + f59eaef commit e3f3fe3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
+ [Get Issue Event](#get-issue-event)
* [SCANNING](#scanning)
+ [Scan Artifact](#scan-artifact)
+ [Scan Build](#scan-build)
<!-- tocstop -->

# Install
Expand Down Expand Up @@ -213,3 +214,13 @@ scanning = xray_rest_client.scanning
response = scanning.scan_artifact("docker://image_name:image_tag")
print(response.json())
```
### Scan Build
```python
scanning = xray_rest_client.scanning
# scan build v1
response = scanning.scan_build("build_name", "build_number")
# scan build v2
# Starting from Xray version 3.42.3
response = scanning.scan_build("build_name", "build_number", api_version='v2')
print(response.json())
```
33 changes: 32 additions & 1 deletion xray/scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,35 @@ def scan_artifact(self, component_id):
)
return response


def scan_build(self, build_name, build_number, api_version='v1'):
"""
Invokes scanning of a build that was uploaded to Artifactory as requested by a CI server
:param build_name:
:param build_number:
:param api_version: api/v2 starting from Xray version 3.42.3
:return:
"""
assert api_version in ['v1', 'v2']
url = ''
json_data = {}
if api_version == 'v1':
url = self.base_url + "/api/v1/scanBuild"
json_data = {
"buildName": build_name,
"buildNumber": build_number,
"rescan": True,
"filters": {
"includeLicenses": True
}
}
elif api_version == 'v2':
url = self.base_url + "/api/v2/ci/build"
json_data = {
"buildName": build_name,
"buildNumber": build_number
}
response = self.rest_post(
url,
json_data=json_data
)
return response

0 comments on commit e3f3fe3

Please sign in to comment.