CodelyTV / pr-size-labeler

🏷 Visualize and optionally limit the size of your Pull Requests
https://github.com/marketplace/actions/pull-request-size-labeler
MIT License
336 stars 58 forks source link

Please consider NGS #30

Closed ilyash-b closed 2 years ago

ilyash-b commented 3 years ago

https://github.com/CodelyTV/pr-size-labeler/blob/48a746c126f0c8aef5ac07dfd7096c2a66b43cc6/src/github.sh#L15-L33

From my biased perspective, as the author, NGS is better fit for this tool. Please consider. Sample, untested, translation of the referenced code follows:

F add_label_to_pr(pr_number, label_to_add) {
    info = ``curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H $GITHUB_API_HEADER "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/pulls/$pr_number"``
    # info is now data structure, the JSON is parsed by ``...`` expression
    labels = info.labels.name.flatten().reject(Pfx('size/')) + [label_to_add]
    labels_arg = {'labels': labels}.encode_json()  # proper handling of all escaping etc
    log("Final labels: ${labels}")  # log() is language built in
    $(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H $GITHUB_API_HEADER -X PATCH -H "Content-Type: application/json" -d $labels_arg "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/issues/$pr_number")
}

$GITHUB_API_HEADER is intentionally not inside double quotes, it is passed as exactly one argument, as is.

organom commented 3 years ago

to install NGS to try it out, you can simply curl https://ngs-lang.org/install.sh | bash

JavierCane commented 2 years ago

Thanks for the suggestion @ilyash-b

However, we would prefer to continue using standard bash in order to avoid setting an entry barrier for understanding or contributing to the GitHub Action