Skip to content

Commit c1820b0

Browse files
authored
Merge pull request majlis-erc#792 from evolvedbinary/hotfix/git-browse
Fix the GitHub browse endpoint
2 parents bd61387 + 0c961e2 commit c1820b0

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/main/xar-resources/services/get-rec.xql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import module namespace rh = "http://localhost/manuForma/request-helper" at "../
99

1010
import module namespace http = "http://expath.org/ns/http-client";
1111
import module namespace request = "http://exist-db.org/xquery/request";
12+
import module namespace response = "http://exist-db.org/xquery/response";
1213

1314
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
1415
declare namespace tei = "http://www.tei-c.org/ns/1.0";
@@ -182,14 +183,16 @@ declare function local:get-data() {
182183

183184
else ()
184185

185-
else if ($local:github = "browse") then
186-
gitcommit:list-files()
187-
188186
else
189187
request:get-data()
190188
};
191189

192190

193-
let $data := local:get-data()
194-
return
195-
local:markdown($data)
191+
if ($local:github = "browse") then
192+
let $json := gitcommit:list-files()
193+
return
194+
response:stream($json, "method=TEXT media-type=application/json")
195+
else
196+
let $data := local:get-data()
197+
return
198+
local:markdown($data)

src/main/xar-resources/services/git-commit.xql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ declare namespace json = "http://www.json.org";
4747
(: Set up global variables :)
4848
declare variable $gitcommit:authorization-token := '${github-pat}';
4949
declare variable $gitcommit:apiURL := 'https://api.github.com';
50-
declare variable $gitcommit:owner := if(request:get-parameter('githubOwner','') != '') then request:get-parameter('githubOwner','') else 'wsalesky';
51-
declare variable $gitcommit:repoName := if(request:get-parameter('githubRepoName','') != '') then request:get-parameter('githubRepoName','') else 'blogs';
52-
declare variable $gitcommit:branch := if(request:get-parameter('githubBranch','') != '') then request:get-parameter('githubBranch','') else 'master';
50+
declare variable $gitcommit:owner := if(request:get-parameter('githubOwner','') != '') then request:get-parameter('githubOwner','') else 'majlis-erc';
51+
declare variable $gitcommit:repoName := if(request:get-parameter('githubRepoName','') != '') then request:get-parameter('githubRepoName','') else 'majlis-data';
52+
declare variable $gitcommit:branch := if(request:get-parameter('githubBranch','') != '') then request:get-parameter('githubBranch','') else 'main';
5353
declare variable $gitcommit:dataPath := if(request:get-parameter('githubPath','') != '') then request:get-parameter('githubPath','') else 'data/tei/';
5454

5555
declare function gitcommit:list-files(){
56-
(:https://github.com/wsalesky/blogs:)
57-
(: https://api.github.com/repos/octocat/hello-world/autolinks/42 :)
58-
(:Step 1: /repos/{owner}/{repo}/contents/{path} :)
56+
(: https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content :)
57+
(: Step 1: /repos/{owner}/{repo}/contents/{path}?ref=branch :)
58+
let $uri := xs:anyURI(concat($gitcommit:apiURL, '/repos/', $gitcommit:owner, '/', $gitcommit:repoName, '/contents/', $gitcommit:dataPath, "?ref=", $gitcommit:branch))
5959
let $request :=
60-
http:send-request(<http:request http-version="1.1" href="{xs:anyURI(concat($gitcommit:apiURL,'/repos/',$gitcommit:owner,'/',$gitcommit:repoName,'/contents/',$gitcommit:branch))}" method="get">
60+
http:send-request(<http:request http-version="1.1" href="{$uri}" method="get">
6161
<http:header name="Authorization" value="{concat('token ',$gitcommit:authorization-token)}"/>
6262
<http:header name="Connection" value="close"/>
6363
</http:request>)

0 commit comments

Comments
 (0)