summaryrefslogtreecommitdiff
path: root/.github/scripts/get-pr-number.es
diff options
context:
space:
mode:
Diffstat (limited to '.github/scripts/get-pr-number.es')
-rwxr-xr-x.github/scripts/get-pr-number.es35
1 files changed, 31 insertions, 4 deletions
diff --git a/.github/scripts/get-pr-number.es b/.github/scripts/get-pr-number.es
index e925f95625..a388e6107a 100755
--- a/.github/scripts/get-pr-number.es
+++ b/.github/scripts/get-pr-number.es
@@ -11,19 +11,46 @@ main([Repo, HeadSha]) ->
string:equal(HeadSha, Sha)
end, AllOpenPrs) of
{value, #{ <<"number">> := Number } } ->
- io:format("::set-output name=result::~p~n", [Number]);
+ append_to_github_output("result=~p~n", [Number]);
false ->
- io:format("::set-output name=result::~ts~n", [""])
+ append_to_github_output("result=~ts~n", [""])
+ end.
+
+append_to_github_output(Fmt, Args) ->
+ case os:getenv("GITHUB_OUTPUT") of
+ false ->
+ io:format(standard_error, "GITHUB_OUTPUT env var missing?~n", []);
+ GitHubOutputFile ->
+ {ok, F} = file:open(GitHubOutputFile, [write, append]),
+ ok = io:fwrite(F, Fmt, Args),
+ ok = file:close(F)
end.
ghapi(CMD) ->
- Data = cmd(CMD),
- try jsx:decode(Data, [{return_maps,true}])
+ decode(cmd(CMD)).
+
+decode(Data) ->
+ try jsx:decode(Data,[{return_maps, true}, return_tail]) of
+ {with_tail, Json, <<>>} ->
+ Json;
+ {with_tail, Json, Tail} ->
+ lists:concat([Json | decodeTail(Tail)])
catch E:R:ST ->
io:format("Failed to decode: ~ts",[Data]),
erlang:raise(E,R,ST)
end.
+decodeTail(Data) ->
+ try jsx:decode(Data,[{return_maps, true}, return_tail]) of
+ {with_tail, Json, <<>>} ->
+ [Json];
+ {with_tail, Json, Tail} ->
+ [Json | decodeTail(Tail)]
+ catch E:R:ST ->
+ io:format(standard_error, "Failed to decode: ~ts",[Data]),
+ erlang:raise(E,R,ST)
+ end.
+
cmd(CMD) ->
ListCmd = unicode:characters_to_list(CMD),
io:format("cmd: ~ts~n",[ListCmd]),