-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
add golang package mirroring #165
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/pre-commit/dummy | ||
|
||
go 1.19 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
func main() {{}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import subprocess | ||
import urllib.request | ||
|
||
import lxml.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should not need an external dependency to read xml -- there's an |
||
from packaging import version | ||
|
||
|
||
|
@@ -31,6 +32,21 @@ def rust_get_package_versions(package_name: str) -> list[str]: | |
return list(reversed([version['num'] for version in resp['versions']])) | ||
|
||
|
||
def golang_get_package_versions(package_name: str) -> list[str]: | ||
url = f'https://pkg.go.dev/{package_name}?tab=versions' | ||
resp = urllib.request.urlopen(url) | ||
versions = lxml.html.parse(resp).xpath( | ||
"//a[@class='js-versionLink']//text()", | ||
) | ||
return [str(version) for version in versions[::-1]] | ||
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not be parsing html to get the answers here -- this needs to come from an actual documented api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know, go doesn't provide an actual documented API, the only workaround was to scrape it : / There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't they just git tags? |
||
|
||
|
||
def golang_get_additional_dependencies( | ||
package_name: str, package_version: str, | ||
) -> list[str]: | ||
return [f'{package_name}@{package_version}'] | ||
|
||
|
||
def node_get_additional_dependencies( | ||
package_name: str, package_version: str, | ||
) -> list[str]: | ||
|
@@ -48,9 +64,11 @@ def rust_get_additional_dependencies( | |
'python': python_get_package_versions, | ||
'ruby': ruby_get_package_versions, | ||
'rust': rust_get_package_versions, | ||
'golang': golang_get_package_versions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order |
||
} | ||
|
||
ADDITIONAL_DEPENDENCIES = { | ||
'node': node_get_additional_dependencies, | ||
'rust': rust_get_additional_dependencies, | ||
'golang': golang_get_additional_dependencies, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ def git(*cmd: str) -> None: | |
# Commit and tag | ||
git('add', '.') | ||
git('commit', '-m', f'Mirror: {version}') | ||
git('tag', f'v{version}') | ||
git('tag', f'v{version.lstrip("v")}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm this seems not right |
||
|
||
|
||
def make_repo(repo: str, *, language: str, name: str, **fmt_vars: str) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ classifiers = | |
[options] | ||
packages = find: | ||
install_requires = | ||
lxml | ||
packaging | ||
python_requires = >=3.7 | ||
|
||
|
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.
please use the word "placeholder" instead as to avoid ableist language