pharo-project / pharo-launcher

Lets you manage your pharo images and download new ones
https://pharo-project.github.io/pharo-launcher/
MIT License
109 stars 46 forks source link

github-release-template-group #496

Closed oliveiraallex closed 4 years ago

oliveiraallex commented 4 years ago

added a new template group to github relases page

oliveiraallex commented 4 years ago

image

demarey commented 4 years ago

Thanks for the PR. By looking at the code I do not think GitHub releases deserves a new class. The use case is generic. You only need to customize the template name.

I would rather enhance PhLHTTPListingTemplateGroup with the ability to specify a custom name. example:

PhLTemplateSource {
        #type : #HttpGithubRelease,
        #name : 'Pharo Remote Development (TelePharo)',
        #url : 'https://github.com/pharo-ide/TelePharo/releases',
        #filterPattern : 'href="([^"]*/Pharo[0-9][^"]*.zip)"'
        #templateNameFormat: '{6} ({5})'
}

{NUMBER} will refer to the url segment index at NUMBER.

Here is a try to implement this behaviour (adaptation of String>>#format):

String >> #formatTemplateName: aUrlString
    "Format the receiver by interpolating elements from url string path segments, as in the following examples:" 
    "('{6} ({5})' format: '/pharo-ide/TelePharo/releases/download/v0.4.2/Pharo7.0-32bit-TelePharo.zip') >>> 'Pharo7.0-32bit-TelePharo (v0.4.2)'"
    "We always remove the extension of the last segment ('.zip)"
    | segments |
    segments:= aUrlString asZnUrl segments.

    ^ self class
        new: self size
        streamContents: [ :result | 
            | stream |
            stream := self readStream.
            [ stream atEnd ]
                whileFalse: [ | currentChar |
                    (currentChar := stream next) == ${
                        ifTrue: [ | expression index value |
                            expression := stream upTo: $}.
                            index := Integer readFrom: expression ifFail: [ expression ].
                            value := segments at: index.
                            result nextPutAll: (index = segments size ifTrue: [ value copyUpToLast: $. ] ifFalse: [ value ]) ]
                        ifFalse: [ currentChar == $\
                                ifTrue: [ stream atEnd
                                        ifFalse: [ result nextPut: stream next ] ]
                                ifFalse: [ result nextPut: currentChar ] ] ] ]

Then in PhLHTTPListingTemplateGroup, you just need to call this method if #templateNameFormat has been defined (should stay optional).

It needs some tests for serialization / deserialization and #formatTemplateName: but it should do what you want without the need of a specific class.

demarey commented 4 years ago

👍

oliveiraallex commented 4 years ago

Thanks @demarey ! I would like to implement 2 things more. What do you think?

1 - A depth option to pass as a parameter, to take the next pages. Or could be the number of tags, like #lastReleaseNumber: 20.

PhLTemplateSource {
        #type : #HttpGithubRelease,
        #name : 'Pharo Remote Development (TelePharo)',
        #url : 'https://github.com/pharo-ide/TelePharo/releases',
        #filterPattern : 'href="([^"]*/Pharo[0-9][^"]*.zip)"',
        #templateNameFormat: '{6} ({5})',
        #depth: '3'
}

2 - A tree hierarchy to group the tagged versions, like this:

PharoThings 9 32 (continuous build) PharoThings 9 64 (continuous build) PharoThings 8 32 (continuous build) PharoThings (v4.0.2) PharoThings (v4.0.1) | PharoThings 9 32 (v4.0.1) | PharoThings 9 64 (v4.0.1) | PharoThings 8 32 (v4.0.1) | PharoThings xxxx (v4.0.1)

demarey commented 4 years ago

for 1: you could specify a maximum of urls to show but how will you filter / sort? I do not see a nice way to do that but I understand the need for 2: you could try to make PhLHTTPListingTemplateGroup return a collection of PhLHTTPListingTemplateGroup themselves returning a list of PhLRemoteTemplate. Doing so would mimic the Jenkins template provider already providing a tree view for jobs.

oliveiraallex commented 4 years ago

1 - With Github I think maybe it's a bit more complicated. I saw now that to go to the next pages they use the tag number to go to next, like (releases?after=v0.2.2). I could do a kind of crawler, but thinking well, maybe it will be better to let this to the future because now it's only one release page... 2 - I will try to do that. Thanks again @demarey !