-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[AlpinePackages] New apline packages bridge #4781
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
base: master
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,186 @@ | ||||||
| <?php | ||||||
|
|
||||||
| declare(strict_types=1); | ||||||
|
|
||||||
| class AlpinePackagesBridge extends BridgeAbstract | ||||||
| { | ||||||
| const NAME = 'Alpine Packages Bridge'; | ||||||
| const MAINTAINER = 'rsd76'; | ||||||
| const URI = 'https://pkgs.alpinelinux.org'; | ||||||
| const DESCRIPTION = 'Bridge for getting Alpine packages versions'; | ||||||
| const CACHE_TIMEOUT = 3600; | ||||||
|
|
||||||
| const PARAMETERS = [ | ||||||
| [ | ||||||
| 'package' => [ | ||||||
| 'type' => 'text', | ||||||
| 'name' => 'Package Name', | ||||||
| 'required' => true, | ||||||
| 'exampleValue' => 'curl', | ||||||
| 'title' => 'Name of the package. Use * and ? as wildcards. Example: curl, curl-* or curl-???' | ||||||
|
Contributor
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. Can you use a consistent package for all three examples you give? E.g.
Suggested change
|
||||||
| ], | ||||||
| 'branch' => [ | ||||||
| 'type' => 'text', | ||||||
| 'name' => 'Package branch', | ||||||
| 'required' => true, | ||||||
| 'exampleValue' => 'v3.23', | ||||||
| 'title' => 'Name of the branch. Like: edge, v3.23, v3.22, etc.' | ||||||
|
Contributor
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.
Suggested change
|
||||||
| ], | ||||||
| 'repository' => [ | ||||||
| 'type' => 'list', | ||||||
| 'name' => 'Repository name', | ||||||
| 'values' => [ | ||||||
| 'All' => 'all', | ||||||
| 'Community' => 'community', | ||||||
| 'Main' => 'main', | ||||||
| 'Testing' => 'testing' | ||||||
| ], | ||||||
| 'defaultValue' => 'all', | ||||||
| 'title' => 'Name of the repository.' | ||||||
|
Contributor
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. I'd delete that if it doesn't add any detail to the |
||||||
| ], | ||||||
| 'architecture' => [ | ||||||
| 'type' => 'text', | ||||||
| 'name' => 'Achitecture', | ||||||
| 'exampleValue' => 'aarch64', | ||||||
| 'title' => 'Architecture of the package. Like: aarch64, armhf, armv7, loongarch64, ppc64le, ppc64le, ppc64le, x86 and x86_64. Keep empty or use "all" for all.' | ||||||
| ] | ||||||
| ] | ||||||
| ]; | ||||||
|
|
||||||
| private function getADom($element) | ||||||
| { | ||||||
| return $element->find('a')[0]; | ||||||
| } | ||||||
|
|
||||||
| private function getElementData($element) | ||||||
| { | ||||||
| $classes = [ | ||||||
| 'package', | ||||||
| 'repo', | ||||||
| 'arch', | ||||||
| 'maintainer' | ||||||
| ]; | ||||||
| $noAhrefClasses = [ | ||||||
| 'branch', | ||||||
| 'bdate' | ||||||
| ]; | ||||||
| $data = []; | ||||||
| // Get data from element which contains <a href=...>. | ||||||
| foreach ($classes as $class) { | ||||||
| $td = $this->getTdClassDom($element, $class); | ||||||
| $a = $this->getADom($td); | ||||||
| $data[$class] = trim($a->plaintext); | ||||||
| $data[$class . '-href'] = $a->href; | ||||||
| } | ||||||
| // Get data from element which only contains text. | ||||||
| foreach ($noAhrefClasses as $class) { | ||||||
| $td = $this->getTdClassDom($element, $class); | ||||||
| $data[$class] = trim($td->plaintext); | ||||||
| } | ||||||
| // Get version data in a <strong> element. | ||||||
| $td = $this->getTdClassDom($element, 'version'); | ||||||
| $strong = $td->find('strong[class=hint--right hint--rounded text-success]')[0]; | ||||||
| $data['version'] = trim($strong->plaintext); | ||||||
| return $data; | ||||||
| } | ||||||
|
|
||||||
| private function getTdClassDom($element, $class) | ||||||
| { | ||||||
| return $element->find('td[class=' . $class . ']')[0]; | ||||||
| } | ||||||
|
|
||||||
| public function collectData() | ||||||
| { | ||||||
| $dom = getSimpleHTMLDOM($this->getUri()); | ||||||
| $dom = defaultLinkTo($dom, self::URI); | ||||||
| $table = $dom->find('table[class=pure-table pure-table-striped]')[0]; | ||||||
| $tbody = $table->find('tbody')[0]; | ||||||
| $trs = $tbody->find('tr'); | ||||||
| foreach ($trs as $tr) { | ||||||
| $itemData = $this->getElementData($tr); | ||||||
| $this->items[] = [ | ||||||
| 'title' => $itemData['package'] . '-' . $itemData['version'], | ||||||
| 'uri' => $itemData['package-href'], | ||||||
| 'timestamp' => strtotime($itemData['bdate']), | ||||||
| 'uid' => trim($itemData['package']) . $itemData['version'] . $itemData['arch'] . $itemData['branch'] . $itemData['repo'], | ||||||
| 'author' => $itemData['maintainer'], | ||||||
| 'categories' => [ | ||||||
| 'arch: ' . $itemData['arch'], | ||||||
| 'branch: ' . $itemData['branch'], | ||||||
| 'repo: ' . $itemData['repo'] | ||||||
| ] | ||||||
| ]; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public function getName() | ||||||
|
Contributor
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. The output is quite a mouthful. Can we develop a more compact representation for the feed name? |
||||||
| { | ||||||
| $packageName = $this->getInput('package'); | ||||||
| $branchName = $this->getInput('branch'); | ||||||
| $repositoryName = $this->getInput('repository'); | ||||||
| $architecture = $this->getInput('architecture'); | ||||||
|
|
||||||
| $name = ''; | ||||||
|
|
||||||
| if ($packageName) { | ||||||
| $packageName = strtolower($packageName); | ||||||
| $name = $packageName; | ||||||
| if ($branchName) { | ||||||
| $branchName = strtolower($branchName); | ||||||
| $name .= ' on branch ' . $branchName; | ||||||
| } | ||||||
| if ($repositoryName) { | ||||||
| $repositoryName = strtolower($repositoryName); | ||||||
| if ($repositoryName === 'all') { | ||||||
|
Contributor
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. This handles "all" different from an empty specification. Please handle them the same (as in |
||||||
| $name .= ' in all repositories'; | ||||||
| } else { | ||||||
| $name .= ' in repository ' . $repositoryName; | ||||||
| } | ||||||
| } | ||||||
| if ($architecture) { | ||||||
| $architecture = strtolower($architecture); | ||||||
| if ($architecture === 'all') { | ||||||
| $name .= ' on all architectures'; | ||||||
| } else { | ||||||
| $name .= ' on ' . $architecture; | ||||||
| } | ||||||
| } | ||||||
| $name .= ' - Alpine packages'; | ||||||
| return $name; | ||||||
| } | ||||||
|
|
||||||
| return parent::getName(); | ||||||
| } | ||||||
|
|
||||||
| public function getUri() | ||||||
| { | ||||||
| $package = $this->getInput('package'); | ||||||
| $branch = $this->getInput('branch'); | ||||||
| $repository = $this->getInput('repository'); | ||||||
| $architecture = $this->getInput('architecture'); | ||||||
|
|
||||||
| if ($package) { | ||||||
| $package = urlencode(strtolower(trim($package))); | ||||||
| } | ||||||
| if ($branch) { | ||||||
| $branch = strtolower(trim($branch)); | ||||||
| } | ||||||
| if ($repository) { | ||||||
| $repository = strtolower($repository); | ||||||
| if ($repository === 'all') { | ||||||
| $repository = ''; | ||||||
| } | ||||||
| } | ||||||
| if ($architecture) { | ||||||
| $architecture = strtolower(trim($architecture)); | ||||||
| if ($architecture === 'all') { | ||||||
| $architecture = ''; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ($package && $branch) { | ||||||
| return self::URI . '/packages?name=' . $package . '&branch=' . $branch . '&repo=' . $repository . '&arch=' . $architecture . '&origin=&flagged=&maintainer='; | ||||||
| } | ||||||
| return self::URI; | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.