Move gh check to the Haskell binary

This commit is contained in:
Eugen Wissner 2023-08-10 12:47:43 +02:00
parent 43ebbc5e67
commit 5a9e87cd5f
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
6 changed files with 16 additions and 40 deletions

View File

@ -166,19 +166,11 @@ module SlackBuilder
end end
end end
php_transform = proc do |version|
version.delete_prefix 'php-' if version.match?(/^php-8\.2\.[[:digit:]+]$/)
end
rdiff_backup_transform = proc do |version|
version.delete_prefix 'v' if version.match?(/^v\d+\.\d+\.\d+/)
end
AUTO_UPDATABLE = { AUTO_UPDATABLE = {
'universal-ctags' => [SlackBuilder::GitHub.new('universal-ctags', 'ctags'), SlackBuilder::UniversalCtags.new], 'universal-ctags' => [SlackBuilder::GitHub.new('universal-ctags', 'ctags'), SlackBuilder::UniversalCtags.new],
'composer' => [SlackBuilder::Packagist.new('composer', 'composer'), SlackBuilder::Composer.new], 'composer' => [SlackBuilder::Packagist.new('composer', 'composer'), SlackBuilder::Composer.new],
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', php_transform), SlackBuilder::PHP.new], 'php82' => [SlackBuilder::GitHub.new('php', 'php-src', 'php'), SlackBuilder::PHP.new],
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', rdiff_backup_transform)], 'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')], 'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
'jitsi-meet-desktop' => [ 'jitsi-meet-desktop' => [
SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron'), SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron'),

View File

@ -19,10 +19,18 @@ main = do
PackagistCommand packagistArguments -> PackagistCommand packagistArguments ->
latestPackagist packagistArguments latestPackagist packagistArguments
TextCommand textArguments -> latestText textArguments TextCommand textArguments -> latestText textArguments
GhCommand ghArguments -> latestGitHub settings ghArguments (stripPrefix "v") GhCommand ghArguments@GhArguments{ transform } ->
latestGitHub settings ghArguments $ chooseTransformFunction transform
Text.IO.putStrLn $ fromMaybe "" latestVersion Text.IO.putStrLn $ fromMaybe "" latestVersion
where where
chooseTransformFunction (Just "php") = phpTransform
chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v"
chooseTransformFunction _ = stripPrefix "v"
stripPrefix prefix string = Just stripPrefix prefix string = Just
$ fromMaybe string $ fromMaybe string
$ Text.stripPrefix prefix string $ Text.stripPrefix prefix string
phpTransform version
| (majorPrefix, patchVersion) <- Text.breakOnEnd "." version
, majorPrefix == "php-8.2." = Just $ Text.drop (Text.length "php-") version
| otherwise = Nothing

View File

@ -16,7 +16,7 @@ import Options.Applicative
, info , info
, fullDesc , fullDesc
, subparser , subparser
, command , command, optional
) )
data SlackBuilderCommand data SlackBuilderCommand
@ -32,6 +32,7 @@ data PackagistArguments = PackagistArguments
data GhArguments = GhArguments data GhArguments = GhArguments
{ owner :: Text { owner :: Text
, name :: Text , name :: Text
, transform :: Maybe Text
} deriving (Eq, Show) } deriving (Eq, Show)
newtype TextArguments = TextArguments Text newtype TextArguments = TextArguments Text
@ -48,6 +49,7 @@ ghArguments :: Parser GhArguments
ghArguments = GhArguments ghArguments = GhArguments
<$> argument str (metavar "OWNER") <$> argument str (metavar "OWNER")
<*> argument str (metavar "NAME") <*> argument str (metavar "NAME")
<*> optional (argument str (metavar "TRANSFORM"))
slackBuilderParser :: ParserInfo SlackBuilderCommand slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc slackBuilderParser = info slackBuilderCommand fullDesc

View File

@ -4,6 +4,5 @@ CONFIG = {
remote_path: 'example.com:/srv/httpd/some/path', remote_path: 'example.com:/srv/httpd/some/path',
download_url: 'https://example.com/some/path', download_url: 'https://example.com/some/path',
branch: 'user/nick/updates', branch: 'user/nick/updates',
gh_token: '',
repository: '../slackbuilds' repository: '../slackbuilds'
}.freeze }.freeze

View File

@ -45,33 +45,7 @@ module SlackBuilder
end end
def latest def latest
if @version_transform.nil? `./bin/slackbuilder github #{@owner} #{@name} #{@version_transform}`.strip
`./bin/slackbuilder github #{@owner} #{@name}`.strip
else
latest_with_transform
end
end
private
def latest_with_transform
post_data = {
'query' => GITHUB_QUERY,
'variables' => { 'name' => @name, 'owner' => @owner }
}
uri = URI('https://api.github.com/graphql')
response = Net::HTTP.post uri, post_data.to_json, {
'content-type' => 'application/json',
'authorization' => "Bearer #{CONFIG[:gh_token]}"
}
filter_versions_from_response JSON.parse(response.body)
end
def filter_versions_from_response(response)
response['data']['repository']['refs']['nodes']
.map { |node| @version_transform.call node['name'] }
.compact
.last
end end
end end

View File

@ -28,6 +28,7 @@ executable slackbuilder
default-extensions: default-extensions:
DataKinds DataKinds
DuplicateRecordFields DuplicateRecordFields
NamedFieldPuns
OverloadedStrings OverloadedStrings
RecordWildCards RecordWildCards
TemplateHaskell TemplateHaskell