generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 34
add on demand package data collection for golang #596 #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chinyeungli
wants to merge
7
commits into
main
Choose a base branch
from
596_add_on-demand_package_data_collection_for_golang
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0882289
#596 - Added code for golang collector and updated the miner code for…
chinyeungli 1c1fbd7
#596 - Working in progress to handle bitbucket.org (It contains a lot…
chinyeungli b0f1a22
#596 - Added the following data collection for golang
chinyeungli 82cb1fb
Correct typo
chinyeungli 18f9413
#596 - Add on-demand package data collection for golang
chinyeungli 905195a
Update minecode/collectors/golang.py
chinyeungli 16e9fac
Merge branch 'main' into 596_add_on-demand_package_data_collection_fo…
chinyeungli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# purldb is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/purldb for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
import logging | ||
|
||
import requests | ||
|
||
|
||
""" | ||
Collect bitbucket packages from bitbucket registries. | ||
""" | ||
|
||
logger = logging.getLogger(__name__) | ||
handler = logging.StreamHandler() | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def bitbucket_get_all_package_version_author(subset_path): | ||
""" | ||
Return a list of all version numbers along with author for the package. | ||
""" | ||
repo_tags = f"https://api.bitbucket.org/2.0/repositories/{subset_path}/refs/tags" | ||
version_author_list = [] | ||
try: | ||
while repo_tags: | ||
response = requests.get(repo_tags) | ||
response.raise_for_status() | ||
data = response.json() | ||
if data["size"] > 0: | ||
# Get all available versions | ||
for item in data["values"]: | ||
version = item["name"] | ||
author = "" | ||
if "target" in item and item["target"]: | ||
if "author" in item["target"] and item["target"]["author"]: | ||
if item["target"]["author"]["type"] == "author": | ||
author = item["target"]["author"]["user"]["display_name"] | ||
version_author_list.append((version, author)) | ||
# Handle pagination | ||
repo_tags = data.get("next", None) | ||
return version_author_list | ||
except requests.exceptions.HTTPError as err: | ||
logger.error(f"HTTP error occurred: {err}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# purldb is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/purldb for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
import logging | ||
|
||
import requests | ||
|
||
|
||
""" | ||
Collect gitlab packages from gitlab registries. | ||
""" | ||
|
||
logger = logging.getLogger(__name__) | ||
handler = logging.StreamHandler() | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def gitlab_get_all_package_version_author(subset_path): | ||
""" | ||
Return a list of all version numbers along with author and author email | ||
for the package. | ||
""" | ||
repo_tags = f"https://gitlab.com/api/v4/projects/{subset_path}/repository/tags" | ||
try: | ||
response = requests.get(repo_tags) | ||
response.raise_for_status() | ||
data = response.json() | ||
version_author_list = [] | ||
# Get all available versions | ||
for item in data: | ||
version = item["name"] | ||
author = item["commit"]["author_name"] | ||
author_email = item["commit"]["author_email"] | ||
version_author_list.append((version, author, author_email)) | ||
return version_author_list | ||
except requests.exceptions.HTTPError as err: | ||
logger.error(f"HTTP error occurred: {err}") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chinyeungli could there be golang packages not from github?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Only golang packages from github use this
map_fetchcode_supported_package
function.Others will use
map_golang_package()