Move gh check to the Haskell binary
This commit is contained in:
parent
43ebbc5e67
commit
5a9e87cd5f
12
Rakefile
12
Rakefile
@ -166,19 +166,11 @@ module SlackBuilder
|
||||
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 = {
|
||||
'universal-ctags' => [SlackBuilder::GitHub.new('universal-ctags', 'ctags'), SlackBuilder::UniversalCtags.new],
|
||||
'composer' => [SlackBuilder::Packagist.new('composer', 'composer'), SlackBuilder::Composer.new],
|
||||
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', php_transform), SlackBuilder::PHP.new],
|
||||
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', rdiff_backup_transform)],
|
||||
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', 'php'), SlackBuilder::PHP.new],
|
||||
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
|
||||
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
|
||||
'jitsi-meet-desktop' => [
|
||||
SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron'),
|
||||
|
10
app/Main.hs
10
app/Main.hs
@ -19,10 +19,18 @@ main = do
|
||||
PackagistCommand packagistArguments ->
|
||||
latestPackagist packagistArguments
|
||||
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
|
||||
where
|
||||
chooseTransformFunction (Just "php") = phpTransform
|
||||
chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v"
|
||||
chooseTransformFunction _ = stripPrefix "v"
|
||||
stripPrefix prefix string = Just
|
||||
$ fromMaybe 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
|
||||
|
@ -16,7 +16,7 @@ import Options.Applicative
|
||||
, info
|
||||
, fullDesc
|
||||
, subparser
|
||||
, command
|
||||
, command, optional
|
||||
)
|
||||
|
||||
data SlackBuilderCommand
|
||||
@ -32,6 +32,7 @@ data PackagistArguments = PackagistArguments
|
||||
data GhArguments = GhArguments
|
||||
{ owner :: Text
|
||||
, name :: Text
|
||||
, transform :: Maybe Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
newtype TextArguments = TextArguments Text
|
||||
@ -48,6 +49,7 @@ ghArguments :: Parser GhArguments
|
||||
ghArguments = GhArguments
|
||||
<$> argument str (metavar "OWNER")
|
||||
<*> argument str (metavar "NAME")
|
||||
<*> optional (argument str (metavar "TRANSFORM"))
|
||||
|
||||
slackBuilderParser :: ParserInfo SlackBuilderCommand
|
||||
slackBuilderParser = info slackBuilderCommand fullDesc
|
||||
|
@ -4,6 +4,5 @@ CONFIG = {
|
||||
remote_path: 'example.com:/srv/httpd/some/path',
|
||||
download_url: 'https://example.com/some/path',
|
||||
branch: 'user/nick/updates',
|
||||
gh_token: '',
|
||||
repository: '../slackbuilds'
|
||||
}.freeze
|
||||
|
@ -45,33 +45,7 @@ module SlackBuilder
|
||||
end
|
||||
|
||||
def latest
|
||||
if @version_transform.nil?
|
||||
`./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
|
||||
`./bin/slackbuilder github #{@owner} #{@name} #{@version_transform}`.strip
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,6 +28,7 @@ executable slackbuilder
|
||||
default-extensions:
|
||||
DataKinds
|
||||
DuplicateRecordFields
|
||||
NamedFieldPuns
|
||||
OverloadedStrings
|
||||
RecordWildCards
|
||||
TemplateHaskell
|
||||
|
Loading…
Reference in New Issue
Block a user