-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get a file from a repo, refactor iterating pages (#7)
* Get a file from a repo, refactor iterating pages * Documentation. * Don't use concat in recursive function, flatten pages instead. * Use the first iteration function (better than mine). Refactor. * Use and test the IReduceInit interface * Documentation * Avoid horizontal scrollbar in readme. * Again * Bump version.
- Loading branch information
1 parent
acd5f47
commit 1a7c8a5
Showing
13 changed files
with
433 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
query getRepoFile($owner: String!, $name: String!, $file: String!) { | ||
repository(owner: $owner, name: $name) { | ||
object(expression: $file) { | ||
... on Blob { | ||
abbreviatedOid | ||
byteSize | ||
commitResourcePath | ||
commitUrl | ||
isBinary | ||
isTruncated | ||
oid | ||
text | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns eamonnsullivan.github-api-lib.files | ||
(:require [eamonnsullivan.github-api-lib.core :as core])) | ||
|
||
|
||
(defn get-file | ||
"Get information and properties on a file in a repo, or nil if the | ||
file doesn't exist. | ||
You can use \"HEAD\" if you want a file on the default branch, but | ||
you aren't sure of its name (e.g. \"main\" or \"master\")." | ||
[access-token owner repo branch filepath] | ||
(let [variables {:owner owner :name repo :file (format "%s:%s" branch filepath)} | ||
response (core/make-graphql-post | ||
access-token | ||
(core/get-graphql "get-file-text-query") | ||
variables) | ||
object (-> response :data :repository :object)] | ||
(when object | ||
(merge {:filepath filepath} object)))) | ||
|
||
(defn get-first-file | ||
"Get the first matching file in a repo. We try each of the files specified | ||
and return the first one that exists or nil if none of them do." | ||
[access-token owner repo branch files] | ||
(loop [files files | ||
result nil] | ||
(if-not (seq files) | ||
result | ||
(let [result (get-file access-token owner repo branch (first files))] | ||
(if (:oid result) | ||
result | ||
(recur (rest files) | ||
nil)))))) |
Oops, something went wrong.