@@ -21,7 +21,7 @@ import net.gleske.jervis.exceptions.JervisException
2121import static net.gleske.jervis.tools.AutoRelease.getScriptFromTemplate
2222
2323/**
24- A simple class to interact with the GitHub v4 API.
24+ A simple class to interact with the GitHub v4 GraphQL API.
2525
2626 <h2>Sample usage</h2>
2727 <p >To run this example, clone Jervis and execute <tt >./gradlew console</tt>
@@ -98,11 +98,23 @@ class GitHubGraphQL implements SimpleRestServiceSupport {
9898 |}
9999 ''' . stripMargin(). trim()
100100
101+ /**
102+ A method which returns the base URL for the GitHub v4 GraphQL API. This
103+ method is not meant to be called by end users.
104+
105+ @return Returns <tt >{@link #gh_api}</tt>.
106+ */
101107 @Override
102108 String baseUrl () {
103109 this . gh_api
104110 }
105111
112+ /**
113+ A method which sets authentication headers. This method is not meant to
114+ be called by end users.
115+
116+ @return Returns HTTP header map with authentication headers set.
117+ */
106118 @Override
107119 Map header (Map http_headers = [:]) {
108120 if (this . getToken()) {
@@ -112,7 +124,8 @@ class GitHubGraphQL implements SimpleRestServiceSupport {
112124 }
113125
114126 /**
115- URL to the <a href =" https://developer.github.com/v4/" target =" _blank" >GitHub v4 API</a>. Default: <tt >https://api.github.com/</tt>
127+ URL to the <a href =" https://developer.github.com/v4/" target =" _blank" >GitHub v4 GraphQL API</a>.
128+ Default: <tt >https://api.github.com/graphql</tt>
116129 */
117130 String gh_api = DEFAULT_URL
118131
@@ -155,6 +168,17 @@ class GitHubGraphQL implements SimpleRestServiceSupport {
155168 }
156169 }
157170
171+ /**
172+ Transforms a GraphQL query and variables into data which can be submitted
173+ with a POST request. This is used by <tt >sendGQL</tt> to submit
174+ transformed GraphQL to the GitHub API v4 GraphQL.
175+
176+ @param query A GraphQL query.
177+ @param variables GraphQL variables meant to be used by a GraphQL query.
178+
179+ @return Stringified data which can be submitted directly to a remote HTTP
180+ service that accepts GraphQL.
181+ */
158182 String getGqlData (String query , String variables = ' ' ) {
159183 Map data = [ query : query ]
160184 if (variables) {
@@ -163,6 +187,19 @@ class GitHubGraphQL implements SimpleRestServiceSupport {
163187 (data as JsonBuilder ). toString()
164188 }
165189
190+ /**
191+ A method for calling the GitHub v4 GraphQL API with a GraphQL query and
192+ variables.
193+
194+ @param graphql A GraphQL query.
195+ @param variables GraphQL variables meant to be used by a GraphQL query.
196+ @param http_method Customize the method to be submitted to the GitHub
197+ GraphQL API. Typically <tt >POST</tt>, but could be
198+ another method if performing a mutation.
199+ @param http_headers Add custom HTTP headers. This does not normally need
200+ to be called but is available for customization.
201+ @return A parsed response from the GitHub v4 GraphQL API.
202+ */
166203 public def sendGQL (String graphql , String variables = ' ' , String http_method = ' POST' , Map http_headers = [:]) {
167204 apiFetch(' ' , http_headers, http_method, getGqlData(graphql, variables))
168205 }
@@ -203,11 +240,29 @@ Map response = github.getJervisYamlFiles('samrocketman', 'jervis')</tt></pre>
203240 jervisYaml1: [
204241 text: 'language: groovy\n'
205242 ]
243+ rootFolder: [
244+ file: [
245+ [
246+ name: ".travis.yml",
247+ type: "blob"
248+ ],
249+ [
250+ name: "src",
251+ type: "tree"
252+ ]
253+ ]
254+ ]
206255 ]
207256]</tt></pre>
208257 <p >The above response indicates there was no
209258 <tt >.jervis.yml</tt>, but there was a <tt >.travis.yml</tt>
210259 file.</p>
260+ <p >Files returned are typically one of three types:</p>
261+ <ul >
262+ <li ><tt >blob</tt> - A file which has contents.</li>
263+ <li ><tt >tree</tt> - A folder which can be recursed into.</li>
264+ <li ><tt >commit</tt> - A Git submodule to a referenced repository.</li>
265+ </ul>
211266 */
212267 public Map getJervisYamlFiles (String owner ,
213268 String repository ,
@@ -222,6 +277,25 @@ Map response = github.getJervisYamlFiles('samrocketman', 'jervis')</tt></pre>
222277 ]
223278 sendGQL(getScriptFromTemplate(graphql_expr_template, binding))?. get(' data' ) ?: [:]
224279 }
280+
281+ /**
282+ Get Jervis YAML from a remote repository. It supports getting YAML from
283+ multiple branches at once (<tt >gitRefs</tt> and from multiple alternate
284+ YAML file locations (<tt >yamlFiles</tt>).
285+
286+ @param repositoryWithOwner
287+ A repository URL which includes the GitHub owner. e.g.
288+ <tt >samrocketman/jervis</tt>.
289+ @param gitRefs A list of get references (branches, tags, commits, etc)
290+ in order to retrieve files. By default, the value
291+ <tt >['refs/heads/master']</tt>.
292+ @param yamlFiles A list of YAML files to try getting the Jervis YAML
293+ contents from. By default, the value is
294+ <tt >['.jervis.yml', '.travis.yml']</tt>.
295+ @return See other <a href =" #getJervisYamlFiles(java.lang.String, java.lang.String, java.util.List, java.util.List)" ><tt >getJervisYamlFiles</tt></a>
296+ which returns the same thing. This method is just overloading
297+ the other.
298+ */
225299 public Map getJervisYamlFiles (String repositoryWithOwner ,
226300 List gitRefs = [' refs/heads/master' ],
227301 List yamlFiles = [' .jervis.yml' , ' .travis.yml' ]) {
0 commit comments