diff --git a/Gopkg.lock b/Gopkg.lock index 97597224a..57dcb8288 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -126,11 +126,11 @@ [[projects]] branch = "master" - digest = "1:2179e0f76ac0c9132d0fb2ee03ce9f8116e72e7f55a251757ca92ebee9ba28a9" + digest = "1:ada4e455379c6fc445389096bf78cfe9878e787e80399875a453a871b855cd32" name = "github.com/google/go-github" packages = ["github"] pruneopts = "" - revision = "c004bf0c02fcab9d87a7f2e2f002fd008bf0784c" + revision = "4076fd7418e5e1b04d32ffba6adf5084891952d5" [[projects]] branch = "master" diff --git a/vendor/github.com/google/go-github/.travis.yml b/vendor/github.com/google/go-github/.travis.yml index f575d459e..3a1f51fcc 100644 --- a/vendor/github.com/google/go-github/.travis.yml +++ b/vendor/github.com/google/go-github/.travis.yml @@ -1,10 +1,13 @@ sudo: false language: go go: - - 1.9.x - - 1.8.x - - 1.7.x + - "1.11.x" + - "1.10.x" + - "1.9.x" - master +env: + global: + - GO111MODULE=on matrix: allow_failures: - go: master diff --git a/vendor/github.com/google/go-github/AUTHORS b/vendor/github.com/google/go-github/AUTHORS index c15c465a4..2868f1715 100644 --- a/vendor/github.com/google/go-github/AUTHORS +++ b/vendor/github.com/google/go-github/AUTHORS @@ -13,48 +13,69 @@ Abhinav Gupta Ahmed Hagy Ainsley Chong Akeda Bagus +Akhil Mohan Alec Thomas Aleks Clark Alex Bramley Alexander Harkness +Allen Sun Amey Sakhadeo Andreas Garnæs Andrew Ryabchun +Andy Grunwald Andy Hume Andy Lindeman Anshuman Bhartiya +Antoine Antoine Pelisse +Anubha Kushwaha +appilon Aravind Arıl Bozoluk Austin Dizzy +Ben Batha Beshr Kayali Beyang Liu Billy Lynch Björn Häuser Brad Harris +Brad Moylan Bradley Falzon +Brandon Cook Brian Egizi Bryan Boreham Cami Diez Carlos Alexandro Becker chandresh-pancholi +Charles Fenwick Elliott Charlie Yan +Chris King Chris Roche Chris Schaefer +Christoph Sassenberg Colin Misare Craig Peterson Cristian Maglie Daehyeok Mun Daniel Leavitt +Daniel Nilsson Dave Du Cros Dave Henderson David Deng +David Jannotta +Davide Zipeto +Dennis Webb +Dhi Aurrahman Diego Lapiduz Dmitri Shuralyov dmnlk Don Petersen Doug Turner Drew Fradette +Eli Uriegas +Elliott Beach +Emerson Wood +eperm erwinvaneyk Fabrice Filippo Valsorda @@ -63,11 +84,15 @@ Francesc Gil Francis Fredrik Jönsson Garrett Squire +George Kontridze Georgy Buranov Gnahz Google Inc. +Grachev Mikhail griffin_stewie +Guillaume Jacquet Guz Alexander +Guðmundur Bjarni Ólafsson Hanno Hecker Hari haran haya14busa @@ -78,13 +103,22 @@ Isao Jonas isqua Jameel Haffejee Jan Kosecki +Javier Campanini +Jeremy Morris +Jesse Newland Jihoon Chung Jimmi Dyson +Joan Saum Joe Tsai +John Barton John Engelman +JP Phillips +jpbelanger-mtl Juan Basso +Julien Garcia Gonzalez Julien Rostand Justin Abrahms +Jusung Lee jzhoucliqr Katrina Owen Keita Urashima @@ -92,52 +126,77 @@ Kevin Burke Konrad Malawski Kookheon Kwon Krzysztof Kowalczyk +Kshitij Saraogi kyokomi Lucas Alcantara Luke Evers +Luke Kysow Luke Roberts Luke Young Maksim Zhylinski Martin-Louis Bright +Marwan Sulaiman Mat Geist +Matt Matt Brender +Matt Gaunt Matt Landis Maxime Bury +Michael Spiegel Michael Tiller Michał Glapa Nathan VanBenschoten +Navaneeth Suresh Neil O'Toole Nick Miyake Nick Spragg +Nikhita Raghunath Noah Zoschke ns-cweber +Oleg Kovalov Ondřej Kupka +Palash Nigam Panagiotis Moustafellos +Parham Alvani Parker Moore +parkhyukjun89 Pavel Shtanko +Pete Wagner +Petr Shevtsov Pierre Carrier Piotr Zurek Quinn Slack Rackspace US, Inc. +Radek Simko +Radliński Ignacy +Rajendra arora RaviTeja Pothana rc1140 Red Hat, Inc. Rob Figueiredo +Rohit Upadhyay Ronak Jain Ruben Vereecken Ryan Lower Sahil Dua saisi Sam Minnée +Sandeep Sukhani Sander van Harmelen +Sanket Payghan +Sarasa Kisaragi Sean Wang +Sebastian Mandrean Sebastian Mæland Pedersen Sevki +Shagun Khemka +shakeelrao Shawn Catanzarite Shawn Smith sona-tar SoundCloud, Ltd. Stian Eikeland +Tasya Aditya Rukmana Thomas Bruyelle Timothée Peignier Trey Tacon @@ -145,8 +204,10 @@ ttacon Varadarajan Aravamudhan Victor Castell Victor Vrantchan +Vlad Ungureanu Will Maier William Bailey +xibz Yann Malet Yannick Utard Yicheng Qin diff --git a/vendor/github.com/google/go-github/CONTRIBUTING.md b/vendor/github.com/google/go-github/CONTRIBUTING.md index 68a23f005..8da635a6e 100644 --- a/vendor/github.com/google/go-github/CONTRIBUTING.md +++ b/vendor/github.com/google/go-github/CONTRIBUTING.md @@ -55,7 +55,7 @@ again. [forking]: https://help.github.com/articles/fork-a-repo [golint]: https://github.com/golang/lint -[golint readme]: https://github.com/golang/lint/blob/master/README +[golint readme]: https://github.com/golang/lint/blob/master/README.md [gocov]: https://github.com/axw/gocov [gocov-html]: https://github.com/matm/gocov-html [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html diff --git a/vendor/github.com/google/go-github/LICENSE b/vendor/github.com/google/go-github/LICENSE index 53d5374a7..28b6486f0 100644 --- a/vendor/github.com/google/go-github/LICENSE +++ b/vendor/github.com/google/go-github/LICENSE @@ -25,317 +25,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ----------- - -Some documentation is taken from the GitHub Developer site -, which is available under the following Creative -Commons Attribution 3.0 License. This applies only to the go-github source -code and would not apply to any compiled binaries. - -THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE -COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY -COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS -AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. - -BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE -TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY -BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS -CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND -CONDITIONS. - -1. Definitions - - a. "Adaptation" means a work based upon the Work, or upon the Work and - other pre-existing works, such as a translation, adaptation, - derivative work, arrangement of music or other alterations of a - literary or artistic work, or phonogram or performance and includes - cinematographic adaptations or any other form in which the Work may be - recast, transformed, or adapted including in any form recognizably - derived from the original, except that a work that constitutes a - Collection will not be considered an Adaptation for the purpose of - this License. For the avoidance of doubt, where the Work is a musical - work, performance or phonogram, the synchronization of the Work in - timed-relation with a moving image ("synching") will be considered an - Adaptation for the purpose of this License. - b. "Collection" means a collection of literary or artistic works, such as - encyclopedias and anthologies, or performances, phonograms or - broadcasts, or other works or subject matter other than works listed - in Section 1(f) below, which, by reason of the selection and - arrangement of their contents, constitute intellectual creations, in - which the Work is included in its entirety in unmodified form along - with one or more other contributions, each constituting separate and - independent works in themselves, which together are assembled into a - collective whole. A work that constitutes a Collection will not be - considered an Adaptation (as defined above) for the purposes of this - License. - c. "Distribute" means to make available to the public the original and - copies of the Work or Adaptation, as appropriate, through sale or - other transfer of ownership. - d. "Licensor" means the individual, individuals, entity or entities that - offer(s) the Work under the terms of this License. - e. "Original Author" means, in the case of a literary or artistic work, - the individual, individuals, entity or entities who created the Work - or if no individual or entity can be identified, the publisher; and in - addition (i) in the case of a performance the actors, singers, - musicians, dancers, and other persons who act, sing, deliver, declaim, - play in, interpret or otherwise perform literary or artistic works or - expressions of folklore; (ii) in the case of a phonogram the producer - being the person or legal entity who first fixes the sounds of a - performance or other sounds; and, (iii) in the case of broadcasts, the - organization that transmits the broadcast. - f. "Work" means the literary and/or artistic work offered under the terms - of this License including without limitation any production in the - literary, scientific and artistic domain, whatever may be the mode or - form of its expression including digital form, such as a book, - pamphlet and other writing; a lecture, address, sermon or other work - of the same nature; a dramatic or dramatico-musical work; a - choreographic work or entertainment in dumb show; a musical - composition with or without words; a cinematographic work to which are - assimilated works expressed by a process analogous to cinematography; - a work of drawing, painting, architecture, sculpture, engraving or - lithography; a photographic work to which are assimilated works - expressed by a process analogous to photography; a work of applied - art; an illustration, map, plan, sketch or three-dimensional work - relative to geography, topography, architecture or science; a - performance; a broadcast; a phonogram; a compilation of data to the - extent it is protected as a copyrightable work; or a work performed by - a variety or circus performer to the extent it is not otherwise - considered a literary or artistic work. - g. "You" means an individual or entity exercising rights under this - License who has not previously violated the terms of this License with - respect to the Work, or who has received express permission from the - Licensor to exercise rights under this License despite a previous - violation. - h. "Publicly Perform" means to perform public recitations of the Work and - to communicate to the public those public recitations, by any means or - process, including by wire or wireless means or public digital - performances; to make available to the public Works in such a way that - members of the public may access these Works from a place and at a - place individually chosen by them; to perform the Work to the public - by any means or process and the communication to the public of the - performances of the Work, including by public digital performance; to - broadcast and rebroadcast the Work by any means including signs, - sounds or images. - i. "Reproduce" means to make copies of the Work by any means including - without limitation by sound or visual recordings and the right of - fixation and reproducing fixations of the Work, including storage of a - protected performance or phonogram in digital form or other electronic - medium. - -2. Fair Dealing Rights. Nothing in this License is intended to reduce, -limit, or restrict any uses free from copyright or rights arising from -limitations or exceptions that are provided for in connection with the -copyright protection under copyright law or other applicable laws. - -3. License Grant. Subject to the terms and conditions of this License, -Licensor hereby grants You a worldwide, royalty-free, non-exclusive, -perpetual (for the duration of the applicable copyright) license to -exercise the rights in the Work as stated below: - - a. to Reproduce the Work, to incorporate the Work into one or more - Collections, and to Reproduce the Work as incorporated in the - Collections; - b. to create and Reproduce Adaptations provided that any such Adaptation, - including any translation in any medium, takes reasonable steps to - clearly label, demarcate or otherwise identify that changes were made - to the original Work. For example, a translation could be marked "The - original work was translated from English to Spanish," or a - modification could indicate "The original work has been modified."; - c. to Distribute and Publicly Perform the Work including as incorporated - in Collections; and, - d. to Distribute and Publicly Perform Adaptations. - e. For the avoidance of doubt: - - i. Non-waivable Compulsory License Schemes. In those jurisdictions in - which the right to collect royalties through any statutory or - compulsory licensing scheme cannot be waived, the Licensor - reserves the exclusive right to collect such royalties for any - exercise by You of the rights granted under this License; - ii. Waivable Compulsory License Schemes. In those jurisdictions in - which the right to collect royalties through any statutory or - compulsory licensing scheme can be waived, the Licensor waives the - exclusive right to collect such royalties for any exercise by You - of the rights granted under this License; and, - iii. Voluntary License Schemes. The Licensor waives the right to - collect royalties, whether individually or, in the event that the - Licensor is a member of a collecting society that administers - voluntary licensing schemes, via that society, from any exercise - by You of the rights granted under this License. - -The above rights may be exercised in all media and formats whether now -known or hereafter devised. The above rights include the right to make -such modifications as are technically necessary to exercise the rights in -other media and formats. Subject to Section 8(f), all rights not expressly -granted by Licensor are hereby reserved. - -4. Restrictions. The license granted in Section 3 above is expressly made -subject to and limited by the following restrictions: - - a. You may Distribute or Publicly Perform the Work only under the terms - of this License. You must include a copy of, or the Uniform Resource - Identifier (URI) for, this License with every copy of the Work You - Distribute or Publicly Perform. You may not offer or impose any terms - on the Work that restrict the terms of this License or the ability of - the recipient of the Work to exercise the rights granted to that - recipient under the terms of the License. You may not sublicense the - Work. You must keep intact all notices that refer to this License and - to the disclaimer of warranties with every copy of the Work You - Distribute or Publicly Perform. When You Distribute or Publicly - Perform the Work, You may not impose any effective technological - measures on the Work that restrict the ability of a recipient of the - Work from You to exercise the rights granted to that recipient under - the terms of the License. This Section 4(a) applies to the Work as - incorporated in a Collection, but this does not require the Collection - apart from the Work itself to be made subject to the terms of this - License. If You create a Collection, upon notice from any Licensor You - must, to the extent practicable, remove from the Collection any credit - as required by Section 4(b), as requested. If You create an - Adaptation, upon notice from any Licensor You must, to the extent - practicable, remove from the Adaptation any credit as required by - Section 4(b), as requested. - b. If You Distribute, or Publicly Perform the Work or any Adaptations or - Collections, You must, unless a request has been made pursuant to - Section 4(a), keep intact all copyright notices for the Work and - provide, reasonable to the medium or means You are utilizing: (i) the - name of the Original Author (or pseudonym, if applicable) if supplied, - and/or if the Original Author and/or Licensor designate another party - or parties (e.g., a sponsor institute, publishing entity, journal) for - attribution ("Attribution Parties") in Licensor's copyright notice, - terms of service or by other reasonable means, the name of such party - or parties; (ii) the title of the Work if supplied; (iii) to the - extent reasonably practicable, the URI, if any, that Licensor - specifies to be associated with the Work, unless such URI does not - refer to the copyright notice or licensing information for the Work; - and (iv) , consistent with Section 3(b), in the case of an Adaptation, - a credit identifying the use of the Work in the Adaptation (e.g., - "French translation of the Work by Original Author," or "Screenplay - based on original Work by Original Author"). The credit required by - this Section 4 (b) may be implemented in any reasonable manner; - provided, however, that in the case of a Adaptation or Collection, at - a minimum such credit will appear, if a credit for all contributing - authors of the Adaptation or Collection appears, then as part of these - credits and in a manner at least as prominent as the credits for the - other contributing authors. For the avoidance of doubt, You may only - use the credit required by this Section for the purpose of attribution - in the manner set out above and, by exercising Your rights under this - License, You may not implicitly or explicitly assert or imply any - connection with, sponsorship or endorsement by the Original Author, - Licensor and/or Attribution Parties, as appropriate, of You or Your - use of the Work, without the separate, express prior written - permission of the Original Author, Licensor and/or Attribution - Parties. - c. Except as otherwise agreed in writing by the Licensor or as may be - otherwise permitted by applicable law, if You Reproduce, Distribute or - Publicly Perform the Work either by itself or as part of any - Adaptations or Collections, You must not distort, mutilate, modify or - take other derogatory action in relation to the Work which would be - prejudicial to the Original Author's honor or reputation. Licensor - agrees that in those jurisdictions (e.g. Japan), in which any exercise - of the right granted in Section 3(b) of this License (the right to - make Adaptations) would be deemed to be a distortion, mutilation, - modification or other derogatory action prejudicial to the Original - Author's honor and reputation, the Licensor will waive or not assert, - as appropriate, this Section, to the fullest extent permitted by the - applicable national law, to enable You to reasonably exercise Your - right under Section 3(b) of this License (right to make Adaptations) - but not otherwise. - -5. Representations, Warranties and Disclaimer - -UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR -OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY -KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, -INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, -FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF -LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, -WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION -OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. - -6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE -LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR -ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES -ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS -BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. Termination - - a. This License and the rights granted hereunder will terminate - automatically upon any breach by You of the terms of this License. - Individuals or entities who have received Adaptations or Collections - from You under this License, however, will not have their licenses - terminated provided such individuals or entities remain in full - compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will - survive any termination of this License. - b. Subject to the above terms and conditions, the license granted here is - perpetual (for the duration of the applicable copyright in the Work). - Notwithstanding the above, Licensor reserves the right to release the - Work under different license terms or to stop distributing the Work at - any time; provided, however that any such election will not serve to - withdraw this License (or any other license that has been, or is - required to be, granted under the terms of this License), and this - License will continue in full force and effect unless terminated as - stated above. - -8. Miscellaneous - - a. Each time You Distribute or Publicly Perform the Work or a Collection, - the Licensor offers to the recipient a license to the Work on the same - terms and conditions as the license granted to You under this License. - b. Each time You Distribute or Publicly Perform an Adaptation, Licensor - offers to the recipient a license to the original Work on the same - terms and conditions as the license granted to You under this License. - c. If any provision of this License is invalid or unenforceable under - applicable law, it shall not affect the validity or enforceability of - the remainder of the terms of this License, and without further action - by the parties to this agreement, such provision shall be reformed to - the minimum extent necessary to make such provision valid and - enforceable. - d. No term or provision of this License shall be deemed waived and no - breach consented to unless such waiver or consent shall be in writing - and signed by the party to be charged with such waiver or consent. - e. This License constitutes the entire agreement between the parties with - respect to the Work licensed here. There are no understandings, - agreements or representations with respect to the Work not specified - here. Licensor shall not be bound by any additional provisions that - may appear in any communication from You. This License may not be - modified without the mutual written agreement of the Licensor and You. - f. The rights granted under, and the subject matter referenced, in this - License were drafted utilizing the terminology of the Berne Convention - for the Protection of Literary and Artistic Works (as amended on - September 28, 1979), the Rome Convention of 1961, the WIPO Copyright - Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 - and the Universal Copyright Convention (as revised on July 24, 1971). - These rights and subject matter take effect in the relevant - jurisdiction in which the License terms are sought to be enforced - according to the corresponding provisions of the implementation of - those treaty provisions in the applicable national law. If the - standard suite of rights granted under applicable copyright law - includes additional rights not granted under this License, such - additional rights are deemed to be included in the License; this - License is not intended to restrict the license of any rights under - applicable law. - - -Creative Commons Notice - - Creative Commons is not a party to this License, and makes no warranty - whatsoever in connection with the Work. Creative Commons will not be - liable to You or any party on any legal theory for any damages - whatsoever, including without limitation any general, special, - incidental or consequential damages arising in connection to this - license. Notwithstanding the foregoing two (2) sentences, if Creative - Commons has expressly identified itself as the Licensor hereunder, it - shall have all rights and obligations of Licensor. - - Except for the limited purpose of indicating to the public that the - Work is licensed under the CCPL, Creative Commons does not authorize - the use by either party of the trademark "Creative Commons" or any - related trademark or logo of Creative Commons without the prior - written consent of Creative Commons. Any permitted use will be in - compliance with Creative Commons' then-current trademark usage - guidelines, as may be published on its website or otherwise made - available upon request from time to time. For the avoidance of doubt, - this trademark restriction does not form part of this License. - - Creative Commons may be contacted at http://creativecommons.org/. diff --git a/vendor/github.com/google/go-github/README.md b/vendor/github.com/google/go-github/README.md index d751b8cd0..6e18a33b2 100644 --- a/vendor/github.com/google/go-github/README.md +++ b/vendor/github.com/google/go-github/README.md @@ -1,21 +1,19 @@ # go-github # +[![GoDoc](https://godoc.org/github.com/google/go-github/github?status.svg)](https://godoc.org/github.com/google/go-github/github) [![Build Status](https://travis-ci.org/google/go-github.svg?branch=master)](https://travis-ci.org/google/go-github) [![Test Coverage](https://coveralls.io/repos/google/go-github/badge.svg?branch=master)](https://coveralls.io/r/google/go-github?branch=master) [![Discuss at go-github@googlegroups.com](https://img.shields.io/badge/discuss-go--github%40googlegroups.com-blue.svg)](https://groups.google.com/group/go-github) + go-github is a Go client library for accessing the [GitHub API v3][]. -**Documentation:** [![GoDoc](https://godoc.org/github.com/google/go-github/github?status.svg)](https://godoc.org/github.com/google/go-github/github) -**Mailing List:** [go-github@googlegroups.com](https://groups.google.com/group/go-github) -**Build Status:** [![Build Status](https://travis-ci.org/google/go-github.svg?branch=master)](https://travis-ci.org/google/go-github) -**Test Coverage:** [![Test Coverage](https://coveralls.io/repos/google/go-github/badge.svg?branch=master)](https://coveralls.io/r/google/go-github?branch=master) - -go-github requires Go version 1.7 or greater. +go-github requires Go version 1.9 or greater. If you're interested in using the [GraphQL API v4][], the recommended library is -[shurcooL/githubql][]. +[shurcooL/githubv4][]. ## Usage ## ```go -import "github.com/google/go-github/github" +import "github.com/google/go-github/v19/github" // with go modules enabled (GO111MODULE=on or outside GOPATH) +import "github.com/google/go-github/github" // with go modules disabled ``` Construct a new GitHub client, then use the various services on the client to @@ -25,7 +23,7 @@ access different parts of the GitHub API. For example: client := github.NewClient(nil) // list all organizations for user "willnorris" -orgs, _, err := client.Organizations.List(ctx, "willnorris", nil) +orgs, _, err := client.Organizations.List(context.Background(), "willnorris", nil) ``` Some API methods have optional parameters that can be passed. For example: @@ -35,13 +33,21 @@ client := github.NewClient(nil) // list public repositories for org "github" opt := &github.RepositoryListByOrgOptions{Type: "public"} -repos, _, err := client.Repositories.ListByOrg(ctx, "github", opt) +repos, _, err := client.Repositories.ListByOrg(context.Background(), "github", opt) ``` The services of a client divide the API into logical chunks and correspond to the structure of the GitHub API documentation at https://developer.github.com/v3/. +NOTE: Using the [context](https://godoc.org/context) package, one can easily +pass cancelation signals and deadlines to various services of the client for +handling a request. In case there is no context available, then `context.Background()` +can be used as a starting point. + +For more sample code snippets, head over to the +[example](https://github.com/google/go-github/tree/master/example) directory. + ### Authentication ### The go-github library does not directly handle authentication. Instead, when @@ -208,7 +214,7 @@ For complete usage of go-github, see the full [package docs][]. [personal API token]: https://github.com/blog/1509-personal-api-tokens [package docs]: https://godoc.org/github.com/google/go-github/github [GraphQL API v4]: https://developer.github.com/v4/ -[shurcooL/githubql]: https://github.com/shurcooL/githubql +[shurcooL/githubv4]: https://github.com/shurcooL/githubv4 ### Integration Tests ### @@ -219,25 +225,37 @@ You can run integration tests from the `test` directory. See the integration tes This library is being initially developed for an internal application at Google, so API methods will likely be implemented in the order that they are needed by that application. You can track the status of implementation in -[this Google spreadsheet][roadmap]. Eventually, I would like to cover the entire -GitHub API, so contributions are of course [always welcome][contributing]. The -calling pattern is pretty well established, so adding new methods is relatively -straightforward. +[this Google spreadsheet][roadmap]. [roadmap]: https://docs.google.com/spreadsheet/ccc?key=0ApoVX4GOiXr-dGNKN1pObFh6ek1DR2FKUjBNZ1FmaEE&usp=sharing -[contributing]: CONTRIBUTING.md +## Contributing ## +I would like to cover the entire GitHub API and contributions are of course always welcome. The +calling pattern is pretty well established, so adding new methods is relatively +straightforward. See [`CONTRIBUTING.md`](CONTRIBUTING.md) for details. -## Google App Engine ## +## Versioning ## -Go on App Engine Classic (which as of this writing uses Go 1.6) can not use -the `"context"` import and still relies on `"golang.org/x/net/context"`. -As a result, if you wish to continue to use `go-github` on App Engine Classic, -you will need to rewrite all the `"context"` imports using the following command: +In general, go-github follows [semver](https://semver.org/) as closely as we +can for tagging releases of the package. For self-contained libraries, the +application of semantic versioning is relatively straightforward and generally +understood. But because go-github is a client library for the GitHub API, which +itself changes behavior, and because we are typically pretty aggressive about +implementing preview features of the GitHub API, we've adopted the following +versioning policy: - gofmt -w -r '"context" -> "golang.org/x/net/context"' *.go +* We increment the **major version** with any incompatible change to + non-preview functionality, including changes to the exported Go API surface + or behavior of the API. +* We increment the **minor version** with any backwards-compatible changes to + functionality, as well as any changes to preview functionality in the GitHub + API. GitHub makes no guarantee about the stability of preview functionality, + so neither do we consider it a stable part of the go-github API. +* We increment the **patch version** with any backwards-compatible bug fixes. -See `with_appengine.go` for more details. +Preview functionality may take the form of entire methods or simply additional +data returned from an otherwise non-preview method. Refer to the GitHub API +documentation for details on preview functionality. ## License ## diff --git a/vendor/github.com/google/go-github/example/appengine/app.go b/vendor/github.com/google/go-github/example/appengine/app.go index 4d6cc30ce..81756b5c3 100644 --- a/vendor/github.com/google/go-github/example/appengine/app.go +++ b/vendor/github.com/google/go-github/example/appengine/app.go @@ -12,7 +12,7 @@ import ( "net/http" "os" - "github.com/google/go-github/github" + "github.com/google/go-github/v19/github" "golang.org/x/oauth2" "google.golang.org/appengine" "google.golang.org/appengine/log" diff --git a/vendor/github.com/google/go-github/example/basicauth/main.go b/vendor/github.com/google/go-github/example/basicauth/main.go index f67c3d66e..2c7f4934c 100644 --- a/vendor/github.com/google/go-github/example/basicauth/main.go +++ b/vendor/github.com/google/go-github/example/basicauth/main.go @@ -16,7 +16,7 @@ import ( "strings" "syscall" - "github.com/google/go-github/github" + "github.com/google/go-github/v19/github" "golang.org/x/crypto/ssh/terminal" ) diff --git a/vendor/github.com/google/go-github/example/commitpr/main.go b/vendor/github.com/google/go-github/example/commitpr/main.go new file mode 100644 index 000000000..b62079a53 --- /dev/null +++ b/vendor/github.com/google/go-github/example/commitpr/main.go @@ -0,0 +1,216 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The commitpr command utilizes go-github as a CLI tool for +// pushing files to a branch and creating a pull request from it. +// It takes an auth token as an environment variable and creates +// the commit and the PR under the account affiliated with that token. +// +// The purpose of this example is to show how to use refs, trees and commits to +// create commits and pull requests. +// +// Note, if you want to push a single file, you probably prefer to use the +// content API. An example is available here: +// https://godoc.org/github.com/google/go-github/github#example-RepositoriesService-CreateFile +// +// Note, for this to work at least 1 commit is needed, so you if you use this +// after creating a repository you might want to make sure you set `AutoInit` to +// `true`. +package main + +import ( + "context" + "errors" + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "strings" + "time" + + "github.com/google/go-github/v19/github" + "golang.org/x/oauth2" +) + +var ( + sourceOwner = flag.String("source-owner", "", "Name of the owner (user or org) of the repo to create the commit in.") + sourceRepo = flag.String("source-repo", "", "Name of repo to create the commit in.") + commitMessage = flag.String("commit-message", "", "Content of the commit message.") + commitBranch = flag.String("commit-branch", "", "Name of branch to create the commit in. If it does not already exists, it will be created using the `base-branch` parameter") + baseBranch = flag.String("base-branch", "master", "Name of branch to create the `commit-branch` from.") + prRepoOwner = flag.String("merge-repo-owner", "", "Name of the owner (user or org) of the repo to create the PR against. If not specified, the value of the `-source-owner` flag will be used.") + prRepo = flag.String("merge-repo", "", "Name of repo to create the PR against. If not specified, the value of the `-source-repo` flag will be used.") + prBranch = flag.String("merge-branch", "master", "Name of branch to create the PR against (the one you want to merge your branch in via the PR).") + prSubject = flag.String("pr-title", "", "Title of the pull request. If not specified, no pull request will be created.") + prDescription = flag.String("pr-text", "", "Text to put in the description of the pull request.") + sourceFiles = flag.String("files", "", `Comma-separated list of files to commit and their location. +The local file is separated by its target location by a semi-colon. +If the file should be in the same location with the same name, you can just put the file name and omit the repetition. +Example: README.md,main.go:github/examples/commitpr/main.go`) + authorName = flag.String("author-name", "", "Name of the author of the commit.") + authorEmail = flag.String("author-email", "", "Email of the author of the commit.") +) + +var client *github.Client +var ctx = context.Background() + +// getRef returns the commit branch reference object if it exists or creates it +// from the base branch before returning it. +func getRef() (ref *github.Reference, err error) { + if ref, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, "refs/heads/"+*commitBranch); err == nil { + return ref, nil + } + + // We consider that an error means the branch has not been found and needs to + // be created. + if *commitBranch == *baseBranch { + return nil, errors.New("The commit branch does not exist but `-base-branch` is the same as `-commit-branch`") + } + + if *baseBranch == "" { + return nil, errors.New("The `-base-branch` should not be set to an empty string when the branch specified by `-commit-branch` does not exists") + } + + var baseRef *github.Reference + if baseRef, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, "refs/heads/"+*baseBranch); err != nil { + return nil, err + } + newRef := &github.Reference{Ref: github.String("refs/heads/" + *commitBranch), Object: &github.GitObject{SHA: baseRef.Object.SHA}} + ref, _, err = client.Git.CreateRef(ctx, *sourceOwner, *sourceRepo, newRef) + return ref, err +} + +// getTree generates the tree to commit based on the given files and the commit +// of the ref you got in getRef. +func getTree(ref *github.Reference) (tree *github.Tree, err error) { + // Create a tree with what to commit. + entries := []github.TreeEntry{} + + // Load each file into the tree. + for _, fileArg := range strings.Split(*sourceFiles, ",") { + file, content, err := getFileContent(fileArg) + if err != nil { + return nil, err + } + entries = append(entries, github.TreeEntry{Path: github.String(file), Type: github.String("blob"), Content: github.String(string(content)), Mode: github.String("100644")}) + } + + tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries) + return tree, err +} + +// getFileContent loads the local content of a file and return the target name +// of the file in the target repository and its contents. +func getFileContent(fileArg string) (targetName string, b []byte, err error) { + var localFile string + files := strings.Split(fileArg, ":") + switch { + case len(files) < 1: + return "", nil, errors.New("empty `-files` parameter") + case len(files) == 1: + localFile = files[0] + targetName = files[0] + default: + localFile = files[0] + targetName = files[1] + } + + b, err = ioutil.ReadFile(localFile) + return targetName, b, err +} + +// createCommit creates the commit in the given reference using the given tree. +func pushCommit(ref *github.Reference, tree *github.Tree) (err error) { + // Get the parent commit to attach the commit to. + parent, _, err := client.Repositories.GetCommit(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA) + if err != nil { + return err + } + // This is not always populated, but is needed. + parent.Commit.SHA = parent.SHA + + // Create the commit using the tree. + date := time.Now() + author := &github.CommitAuthor{Date: &date, Name: authorName, Email: authorEmail} + commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []github.Commit{*parent.Commit}} + newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit) + if err != nil { + return err + } + + // Attach the commit to the master branch. + ref.Object.SHA = newCommit.SHA + _, _, err = client.Git.UpdateRef(ctx, *sourceOwner, *sourceRepo, ref, false) + return err +} + +// createPR creates a pull requesit. Based on: https://godoc.org/github.com/google/go-github/github#example-PullRequestsService-Create +func createPR() (err error) { + if *prSubject == "" { + return errors.New("missing `-pr-title` flag; skipping PR creation") + } + + if *prRepoOwner != "" && *prRepoOwner != *sourceOwner { + *commitBranch = fmt.Sprintf("%s:%s", *sourceOwner, *commitBranch) + } else { + prRepoOwner = sourceOwner + } + + if *prRepo == "" { + prRepo = sourceRepo + } + + newPR := &github.NewPullRequest{ + Title: prSubject, + Head: commitBranch, + Base: prBranch, + Body: prDescription, + MaintainerCanModify: github.Bool(true), + } + + pr, _, err := client.PullRequests.Create(ctx, *prRepoOwner, *prRepo, newPR) + if err != nil { + return err + } + + fmt.Printf("PR created: %s\n", pr.GetHTMLURL()) + return nil +} + +func main() { + flag.Parse() + token := os.Getenv("GITHUB_AUTH_TOKEN") + if token == "" { + log.Fatal("Unauthorized: No token present") + } + if *sourceOwner == "" || *sourceRepo == "" || *commitBranch == "" || *sourceFiles == "" || *authorName == "" || *authorEmail == "" { + log.Fatal("You need to specify a non-empty value for the flags `-source-owner`, `-source-repo`, `-commit-branch`, `-files`, `-author-name` and `-author-email`") + } + ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) + tc := oauth2.NewClient(ctx, ts) + client = github.NewClient(tc) + + ref, err := getRef() + if err != nil { + log.Fatalf("Unable to get/create the commit reference: %s\n", err) + } + if ref == nil { + log.Fatalf("No error where returned but the reference is nil") + } + + tree, err := getTree(ref) + if err != nil { + log.Fatalf("Unable to create the tree based on the provided files: %s\n", err) + } + + if err := pushCommit(ref, tree); err != nil { + log.Fatalf("Unable to create the commit: %s\n", err) + } + + if err := createPR(); err != nil { + log.Fatalf("Error while creating the pull request: %s", err) + } +} diff --git a/vendor/github.com/google/go-github/example/migrations/main.go b/vendor/github.com/google/go-github/example/migrations/main.go new file mode 100644 index 000000000..8a80252fd --- /dev/null +++ b/vendor/github.com/google/go-github/example/migrations/main.go @@ -0,0 +1,41 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// migrations demonstrates the functionality of +// the user data migration API for the authenticated GitHub +// user and lists all the user migrations. +package main + +import ( + "context" + "fmt" + + "github.com/google/go-github/v19/github" + "golang.org/x/oauth2" +) + +func fetchAllUserMigrations() ([]*github.UserMigration, error) { + ctx := context.Background() + ts := oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: ""}, + ) + tc := oauth2.NewClient(ctx, ts) + client := github.NewClient(tc) + + migrations, _, err := client.Migrations.ListUserMigrations(ctx) + return migrations, err +} + +func main() { + migrations, err := fetchAllUserMigrations() + if err != nil { + fmt.Printf("Error %v\n", err) + return + } + + for i, m := range migrations { + fmt.Printf("%v. %v", i+1, m.GetID()) + } +} diff --git a/vendor/github.com/google/go-github/example/newrepo/main.go b/vendor/github.com/google/go-github/example/newrepo/main.go new file mode 100644 index 000000000..af3127a49 --- /dev/null +++ b/vendor/github.com/google/go-github/example/newrepo/main.go @@ -0,0 +1,49 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The newrepo command utilizes go-github as a cli tool for +// creating new repositories. It takes an auth token as +// an enviroment variable and creates the new repo under +// the account affiliated with that token. +package main + +import ( + "context" + "flag" + "fmt" + "log" + "os" + + "github.com/google/go-github/v19/github" + "golang.org/x/oauth2" +) + +var ( + name = flag.String("name", "", "Name of repo to create in authenticated user's GitHub account.") + description = flag.String("description", "", "Description of created repo.") + private = flag.Bool("private", false, "Will created repo be private.") +) + +func main() { + flag.Parse() + token := os.Getenv("GITHUB_AUTH_TOKEN") + if token == "" { + log.Fatal("Unauthorized: No token present") + } + if *name == "" { + log.Fatal("No name: New repos must be given a name") + } + ctx := context.Background() + ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) + tc := oauth2.NewClient(ctx, ts) + client := github.NewClient(tc) + + r := &github.Repository{Name: name, Private: private, Description: description} + repo, _, err := client.Repositories.Create(ctx, "", r) + if err != nil { + log.Fatal(err) + } + fmt.Printf("Successfully created new repo: %v\n", repo.GetName()) +} diff --git a/vendor/github.com/google/go-github/example/simple/main.go b/vendor/github.com/google/go-github/example/simple/main.go new file mode 100644 index 000000000..02da00f83 --- /dev/null +++ b/vendor/github.com/google/go-github/example/simple/main.go @@ -0,0 +1,40 @@ +// Copyright 2017 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The simple command demonstrates a simple functionality which +// prompts the user for a GitHub username and lists all the public +// organization memberships of the specified username. +package main + +import ( + "context" + "fmt" + + "github.com/google/go-github/v19/github" +) + +// Fetch all the public organizations' membership of a user. +// +func FetchOrganizations(username string) ([]*github.Organization, error) { + client := github.NewClient(nil) + orgs, _, err := client.Organizations.List(context.Background(), username, nil) + return orgs, err +} + +func main() { + var username string + fmt.Print("Enter GitHub username: ") + fmt.Scanf("%s", &username) + + organizations, err := FetchOrganizations(username) + if err != nil { + fmt.Printf("Error: %v\n", err) + return + } + + for i, organization := range organizations { + fmt.Printf("%v. %v\n", i+1, organization.GetLogin()) + } +} diff --git a/vendor/github.com/google/go-github/github/activity_events.go b/vendor/github.com/google/go-github/github/activity_events.go index 6b35056f4..1754b78e9 100644 --- a/vendor/github.com/google/go-github/github/activity_events.go +++ b/vendor/github.com/google/go-github/github/activity_events.go @@ -7,116 +7,9 @@ package github import ( "context" - "encoding/json" "fmt" - "time" ) -// Event represents a GitHub event. -type Event struct { - Type *string `json:"type,omitempty"` - Public *bool `json:"public"` - RawPayload *json.RawMessage `json:"payload,omitempty"` - Repo *Repository `json:"repo,omitempty"` - Actor *User `json:"actor,omitempty"` - Org *Organization `json:"org,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - ID *string `json:"id,omitempty"` -} - -func (e Event) String() string { - return Stringify(e) -} - -// ParsePayload parses the event payload. For recognized event types, -// a value of the corresponding struct type will be returned. -func (e *Event) ParsePayload() (payload interface{}, err error) { - switch *e.Type { - case "CommitCommentEvent": - payload = &CommitCommentEvent{} - case "CreateEvent": - payload = &CreateEvent{} - case "DeleteEvent": - payload = &DeleteEvent{} - case "DeploymentEvent": - payload = &DeploymentEvent{} - case "DeploymentStatusEvent": - payload = &DeploymentStatusEvent{} - case "ForkEvent": - payload = &ForkEvent{} - case "GollumEvent": - payload = &GollumEvent{} - case "InstallationEvent": - payload = &InstallationEvent{} - case "InstallationRepositoriesEvent": - payload = &InstallationRepositoriesEvent{} - case "IssueCommentEvent": - payload = &IssueCommentEvent{} - case "IssuesEvent": - payload = &IssuesEvent{} - case "LabelEvent": - payload = &LabelEvent{} - case "MemberEvent": - payload = &MemberEvent{} - case "MembershipEvent": - payload = &MembershipEvent{} - case "MilestoneEvent": - payload = &MilestoneEvent{} - case "OrganizationEvent": - payload = &OrganizationEvent{} - case "OrgBlockEvent": - payload = &OrgBlockEvent{} - case "PageBuildEvent": - payload = &PageBuildEvent{} - case "PingEvent": - payload = &PingEvent{} - case "ProjectEvent": - payload = &ProjectEvent{} - case "ProjectCardEvent": - payload = &ProjectCardEvent{} - case "ProjectColumnEvent": - payload = &ProjectColumnEvent{} - case "PublicEvent": - payload = &PublicEvent{} - case "PullRequestEvent": - payload = &PullRequestEvent{} - case "PullRequestReviewEvent": - payload = &PullRequestReviewEvent{} - case "PullRequestReviewCommentEvent": - payload = &PullRequestReviewCommentEvent{} - case "PushEvent": - payload = &PushEvent{} - case "ReleaseEvent": - payload = &ReleaseEvent{} - case "RepositoryEvent": - payload = &RepositoryEvent{} - case "StatusEvent": - payload = &StatusEvent{} - case "TeamEvent": - payload = &TeamEvent{} - case "TeamAddEvent": - payload = &TeamAddEvent{} - case "WatchEvent": - payload = &WatchEvent{} - } - err = json.Unmarshal(*e.RawPayload, &payload) - return payload, err -} - -// Payload returns the parsed event payload. For recognized event types, -// a value of the corresponding struct type will be returned. -// -// Deprecated: Use ParsePayload instead, which returns an error -// rather than panics if JSON unmarshaling raw payload fails. -func (e *Event) Payload() (payload interface{}) { - var err error - payload, err = e.ParsePayload() - if err != nil { - panic(err) - } - return payload -} - // ListEvents drinks from the firehose of all public events across GitHub. // // GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events diff --git a/vendor/github.com/google/go-github/github/activity_events_test.go b/vendor/github.com/google/go-github/github/activity_events_test.go index 2b59d11be..0b01c4a02 100644 --- a/vendor/github.com/google/go-github/github/activity_events_test.go +++ b/vendor/github.com/google/go-github/github/activity_events_test.go @@ -15,7 +15,7 @@ import ( ) func TestActivityService_ListEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestActivityService_ListEvents(t *testing.T) { } func TestActivityService_ListRepositoryEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/events", func(w http.ResponseWriter, r *http.Request) { @@ -63,12 +63,15 @@ func TestActivityService_ListRepositoryEvents(t *testing.T) { } func TestActivityService_ListRepositoryEvents_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListRepositoryEvents(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListIssueEventsForRepository(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events", func(w http.ResponseWriter, r *http.Request) { @@ -85,19 +88,22 @@ func TestActivityService_ListIssueEventsForRepository(t *testing.T) { t.Errorf("Activities.ListIssueEventsForRepository returned error: %v", err) } - want := []*IssueEvent{{ID: Int(1)}, {ID: Int(2)}} + want := []*IssueEvent{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(events, want) { t.Errorf("Activities.ListIssueEventsForRepository returned %+v, want %+v", events, want) } } func TestActivityService_ListIssueEventsForRepository_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListIssueEventsForRepository(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsForRepoNetwork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/networks/o/r/events", func(w http.ResponseWriter, r *http.Request) { @@ -121,12 +127,15 @@ func TestActivityService_ListEventsForRepoNetwork(t *testing.T) { } func TestActivityService_ListEventsForRepoNetwork_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsForRepoNetwork(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsForOrganization(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/events", func(w http.ResponseWriter, r *http.Request) { @@ -150,12 +159,15 @@ func TestActivityService_ListEventsForOrganization(t *testing.T) { } func TestActivityService_ListEventsForOrganization_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsForOrganization(context.Background(), "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events", func(w http.ResponseWriter, r *http.Request) { @@ -179,7 +191,7 @@ func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) { } func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events/public", func(w http.ResponseWriter, r *http.Request) { @@ -199,12 +211,15 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) { } func TestActivityService_ListEventsPerformedByUser_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "%", false, nil) testURLParseError(t, err) } func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/received_events", func(w http.ResponseWriter, r *http.Request) { @@ -228,7 +243,7 @@ func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) { } func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/received_events/public", func(w http.ResponseWriter, r *http.Request) { @@ -248,12 +263,15 @@ func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) { } func TestActivityService_ListEventsReceivedByUser_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "%", false, nil) testURLParseError(t, err) } func TestActivityService_ListUserEventsForOrganization(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events/orgs/o", func(w http.ResponseWriter, r *http.Request) { @@ -283,7 +301,7 @@ func TestActivityService_EventParsePayload_typed(t *testing.T) { t.Fatalf("Unmarshal Event returned error: %v", err) } - want := &PushEvent{PushID: Int(1)} + want := &PushEvent{PushID: Int64(1)} got, err := event.ParsePayload() if err != nil { t.Fatalf("ParsePayload returned unexpected error: %v", err) @@ -320,7 +338,7 @@ func TestActivityService_EventParsePayload_installation(t *testing.T) { t.Fatalf("Unmarshal Event returned error: %v", err) } - want := &PullRequestEvent{Installation: &Installation{ID: Int(1)}} + want := &PullRequestEvent{Installation: &Installation{ID: Int64(1)}} got, err := event.ParsePayload() if err != nil { t.Fatalf("ParsePayload returned unexpected error: %v", err) diff --git a/vendor/github.com/google/go-github/github/activity_notifications_test.go b/vendor/github.com/google/go-github/github/activity_notifications_test.go index cab8f94da..a36b253da 100644 --- a/vendor/github.com/google/go-github/github/activity_notifications_test.go +++ b/vendor/github.com/google/go-github/github/activity_notifications_test.go @@ -16,7 +16,7 @@ import ( ) func TestActivityService_ListNotification(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -34,8 +34,8 @@ func TestActivityService_ListNotification(t *testing.T) { opt := &NotificationListOptions{ All: true, Participating: true, - Since: time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC), - Before: time.Date(2007, 03, 04, 15, 04, 05, 0, time.UTC), + Since: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC), + Before: time.Date(2007, time.March, 04, 15, 04, 05, 0, time.UTC), } notifications, _, err := client.Activity.ListNotifications(context.Background(), opt) if err != nil { @@ -49,7 +49,7 @@ func TestActivityService_ListNotification(t *testing.T) { } func TestActivityService_ListRepositoryNotification(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -69,7 +69,7 @@ func TestActivityService_ListRepositoryNotification(t *testing.T) { } func TestActivityService_MarkNotificationsRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -80,14 +80,14 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) { w.WriteHeader(http.StatusResetContent) }) - _, err := client.Activity.MarkNotificationsRead(context.Background(), time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)) + _, err := client.Activity.MarkNotificationsRead(context.Background(), time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)) if err != nil { t.Errorf("Activity.MarkNotificationsRead returned error: %v", err) } } func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -98,14 +98,14 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { w.WriteHeader(http.StatusResetContent) }) - _, err := client.Activity.MarkRepositoryNotificationsRead(context.Background(), "o", "r", time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)) + _, err := client.Activity.MarkRepositoryNotificationsRead(context.Background(), "o", "r", time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)) if err != nil { t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err) } } func TestActivityService_GetThread(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) { @@ -125,7 +125,7 @@ func TestActivityService_GetThread(t *testing.T) { } func TestActivityService_MarkThreadRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) { @@ -140,7 +140,7 @@ func TestActivityService_MarkThreadRead(t *testing.T) { } func TestActivityService_GetThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -160,7 +160,7 @@ func TestActivityService_GetThreadSubscription(t *testing.T) { } func TestActivityService_SetThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Subscription{Subscribed: Bool(true)} @@ -189,7 +189,7 @@ func TestActivityService_SetThreadSubscription(t *testing.T) { } func TestActivityService_DeleteThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/activity_star.go b/vendor/github.com/google/go-github/github/activity_star.go index d5b067127..5ae5c1016 100644 --- a/vendor/github.com/google/go-github/github/activity_star.go +++ b/vendor/github.com/google/go-github/github/activity_star.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "strings" ) // StarredRepository is returned by ListStarred. @@ -84,8 +85,9 @@ func (s *ActivityService) ListStarred(ctx context.Context, user string, opt *Act return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeStarringPreview) + // TODO: remove custom Accept header when APIs fully launch + acceptHeaders := []string{mediaTypeStarringPreview, mediaTypeTopicsPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) var repos []*StarredRepository resp, err := s.client.Do(ctx, req, &repos) diff --git a/vendor/github.com/google/go-github/github/activity_star_test.go b/vendor/github.com/google/go-github/github/activity_star_test.go index 542bfc66b..8a122478e 100644 --- a/vendor/github.com/google/go-github/github/activity_star_test.go +++ b/vendor/github.com/google/go-github/github/activity_star_test.go @@ -10,12 +10,13 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" "time" ) func TestActivityService_ListStargazers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stargazers", func(w http.ResponseWriter, r *http.Request) { @@ -33,19 +34,19 @@ func TestActivityService_ListStargazers(t *testing.T) { t.Errorf("Activity.ListStargazers returned error: %v", err) } - want := []*Stargazer{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, User: &User{ID: Int(1)}}} + want := []*Stargazer{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, User: &User{ID: Int64(1)}}} if !reflect.DeepEqual(stargazers, want) { t.Errorf("Activity.ListStargazers returned %+v, want %+v", stargazers, want) } } func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeStarringPreview) + testHeader(t, r, "Accept", strings.Join([]string{mediaTypeStarringPreview, mediaTypeTopicsPreview}, ", ")) fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":1}}]`) }) @@ -54,19 +55,19 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int(1)}}} + want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int64(1)}}} if !reflect.DeepEqual(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } } func TestActivityService_ListStarred_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeStarringPreview) + testHeader(t, r, "Accept", strings.Join([]string{mediaTypeStarringPreview, mediaTypeTopicsPreview}, ", ")) testFormValues(t, r, values{ "sort": "created", "direction": "asc", @@ -81,19 +82,22 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int(2)}}} + want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int64(2)}}} if !reflect.DeepEqual(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } } func TestActivityService_ListStarred_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListStarred(context.Background(), "%", nil) testURLParseError(t, err) } func TestActivityService_IsStarred_hasStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -111,7 +115,7 @@ func TestActivityService_IsStarred_hasStar(t *testing.T) { } func TestActivityService_IsStarred_noStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -129,12 +133,15 @@ func TestActivityService_IsStarred_noStar(t *testing.T) { } func TestActivityService_IsStarred_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.IsStarred(context.Background(), "%", "%") testURLParseError(t, err) } func TestActivityService_Star(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -148,12 +155,15 @@ func TestActivityService_Star(t *testing.T) { } func TestActivityService_Star_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Activity.Star(context.Background(), "%", "%") testURLParseError(t, err) } func TestActivityService_Unstar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -167,6 +177,9 @@ func TestActivityService_Unstar(t *testing.T) { } func TestActivityService_Unstar_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Activity.Unstar(context.Background(), "%", "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/activity_test.go b/vendor/github.com/google/go-github/github/activity_test.go index 98567a254..92b42d3a7 100644 --- a/vendor/github.com/google/go-github/github/activity_test.go +++ b/vendor/github.com/google/go-github/github/activity_test.go @@ -13,7 +13,7 @@ import ( ) func TestActivityService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/feeds", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/activity_watching_test.go b/vendor/github.com/google/go-github/github/activity_watching_test.go index d765f67e9..b017d8d59 100644 --- a/vendor/github.com/google/go-github/github/activity_watching_test.go +++ b/vendor/github.com/google/go-github/github/activity_watching_test.go @@ -15,7 +15,7 @@ import ( ) func TestActivityService_ListWatchers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscribers", func(w http.ResponseWriter, r *http.Request) { @@ -32,14 +32,14 @@ func TestActivityService_ListWatchers(t *testing.T) { t.Errorf("Activity.ListWatchers returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(watchers, want) { t.Errorf("Activity.ListWatchers returned %+v, want %+v", watchers, want) } } func TestActivityService_ListWatched_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/subscriptions", func(w http.ResponseWriter, r *http.Request) { @@ -55,14 +55,14 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) { t.Errorf("Activity.ListWatched returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(watched, want) { t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want) } } func TestActivityService_ListWatched_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/subscriptions", func(w http.ResponseWriter, r *http.Request) { @@ -78,14 +78,14 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) { t.Errorf("Activity.ListWatched returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(watched, want) { t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want) } } func TestActivityService_GetRepositorySubscription_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -105,7 +105,7 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) { } func TestActivityService_GetRepositorySubscription_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -125,7 +125,7 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) { } func TestActivityService_GetRepositorySubscription_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -140,7 +140,7 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) { } func TestActivityService_SetRepositorySubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Subscription{Subscribed: Bool(true)} @@ -169,7 +169,7 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) { } func TestActivityService_DeleteRepositorySubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/admin.go b/vendor/github.com/google/go-github/github/admin.go index d0f055bcf..2d96733a1 100644 --- a/vendor/github.com/google/go-github/github/admin.go +++ b/vendor/github.com/google/go-github/github/admin.go @@ -19,7 +19,7 @@ type AdminService service // TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group. type TeamLDAPMapping struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` LDAPDN *string `json:"ldap_dn,omitempty"` URL *string `json:"url,omitempty"` Name *string `json:"name,omitempty"` @@ -38,7 +38,7 @@ func (m TeamLDAPMapping) String() string { // UserLDAPMapping represents the mapping between a GitHub user and an LDAP user. type UserLDAPMapping struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` LDAPDN *string `json:"ldap_dn,omitempty"` Login *string `json:"login,omitempty"` AvatarURL *string `json:"avatar_url,omitempty"` @@ -84,7 +84,7 @@ func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, m // UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group. // // GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team -func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { +func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) req, err := s.client.NewRequest("PATCH", u, mapping) if err != nil { diff --git a/vendor/github.com/google/go-github/github/admin_stats.go b/vendor/github.com/google/go-github/github/admin_stats.go new file mode 100644 index 000000000..b5645f8c1 --- /dev/null +++ b/vendor/github.com/google/go-github/github/admin_stats.go @@ -0,0 +1,171 @@ +// Copyright 2017 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// AdminStats represents a variety of stats of a Github Enterprise +// installation. +type AdminStats struct { + Issues *IssueStats `json:"issues,omitempty"` + Hooks *HookStats `json:"hooks,omitempty"` + Milestones *MilestoneStats `json:"milestones,omitempty"` + Orgs *OrgStats `json:"orgs,omitempty"` + Comments *CommentStats `json:"comments,omitempty"` + Pages *PageStats `json:"pages,omitempty"` + Users *UserStats `json:"users,omitempty"` + Gists *GistStats `json:"gists,omitempty"` + Pulls *PullStats `json:"pulls,omitempty"` + Repos *RepoStats `json:"repos,omitempty"` +} + +func (s AdminStats) String() string { + return Stringify(s) +} + +// IssueStats represents the number of total, open and closed issues. +type IssueStats struct { + TotalIssues *int `json:"total_issues,omitempty"` + OpenIssues *int `json:"open_issues,omitempty"` + ClosedIssues *int `json:"closed_issues,omitempty"` +} + +func (s IssueStats) String() string { + return Stringify(s) +} + +// HookStats represents the number of total, active and inactive hooks. +type HookStats struct { + TotalHooks *int `json:"total_hooks,omitempty"` + ActiveHooks *int `json:"active_hooks,omitempty"` + InactiveHooks *int `json:"inactive_hooks,omitempty"` +} + +func (s HookStats) String() string { + return Stringify(s) +} + +// MilestoneStats represents the number of total, open and close milestones. +type MilestoneStats struct { + TotalMilestones *int `json:"total_milestones,omitempty"` + OpenMilestones *int `json:"open_milestones,omitempty"` + ClosedMilestones *int `json:"closed_milestones,omitempty"` +} + +func (s MilestoneStats) String() string { + return Stringify(s) +} + +// OrgStats represents the number of total, disabled organizations and the team +// and team member count. +type OrgStats struct { + TotalOrgs *int `json:"total_orgs,omitempty"` + DisabledOrgs *int `json:"disabled_orgs,omitempty"` + TotalTeams *int `json:"total_teams,omitempty"` + TotalTeamMembers *int `json:"total_team_members,omitempty"` +} + +func (s OrgStats) String() string { + return Stringify(s) +} + +// CommentStats represents the number of total comments on commits, gists, issues +// and pull requests. +type CommentStats struct { + TotalCommitComments *int `json:"total_commit_comments,omitempty"` + TotalGistComments *int `json:"total_gist_comments,omitempty"` + TotalIssueComments *int `json:"total_issue_comments,omitempty"` + TotalPullRequestComments *int `json:"total_pull_request_comments,omitempty"` +} + +func (s CommentStats) String() string { + return Stringify(s) +} + +// PageStats represents the total number of github pages. +type PageStats struct { + TotalPages *int `json:"total_pages,omitempty"` +} + +func (s PageStats) String() string { + return Stringify(s) +} + +// UserStats represents the number of total, admin and suspended users. +type UserStats struct { + TotalUsers *int `json:"total_users,omitempty"` + AdminUsers *int `json:"admin_users,omitempty"` + SuspendedUsers *int `json:"suspended_users,omitempty"` +} + +func (s UserStats) String() string { + return Stringify(s) +} + +// GistStats represents the number of total, private and public gists. +type GistStats struct { + TotalGists *int `json:"total_gists,omitempty"` + PrivateGists *int `json:"private_gists,omitempty"` + PublicGists *int `json:"public_gists,omitempty"` +} + +func (s GistStats) String() string { + return Stringify(s) +} + +// PullStats represents the number of total, merged, mergable and unmergeable +// pull-requests. +type PullStats struct { + TotalPulls *int `json:"total_pulls,omitempty"` + MergedPulls *int `json:"merged_pulls,omitempty"` + MergablePulls *int `json:"mergeable_pulls,omitempty"` + UnmergablePulls *int `json:"unmergeable_pulls,omitempty"` +} + +func (s PullStats) String() string { + return Stringify(s) +} + +// RepoStats represents the number of total, root, fork, organization repositories +// together with the total number of pushes and wikis. +type RepoStats struct { + TotalRepos *int `json:"total_repos,omitempty"` + RootRepos *int `json:"root_repos,omitempty"` + ForkRepos *int `json:"fork_repos,omitempty"` + OrgRepos *int `json:"org_repos,omitempty"` + TotalPushes *int `json:"total_pushes,omitempty"` + TotalWikis *int `json:"total_wikis,omitempty"` +} + +func (s RepoStats) String() string { + return Stringify(s) +} + +// GetAdminStats returns a variety of metrics about a Github Enterprise +// installation. +// +// Please note that this is only available to site administrators, +// otherwise it will error with a 404 not found (instead of 401 or 403). +// +// GitHub API docs: https://developer.github.com/v3/enterprise-admin/admin_stats/ +func (s *AdminService) GetAdminStats(ctx context.Context) (*AdminStats, *Response, error) { + u := fmt.Sprintf("enterprise/stats/all") + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + m := new(AdminStats) + resp, err := s.client.Do(ctx, req, m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/admin_stats_test.go b/vendor/github.com/google/go-github/github/admin_stats_test.go new file mode 100644 index 000000000..9433adc37 --- /dev/null +++ b/vendor/github.com/google/go-github/github/admin_stats_test.go @@ -0,0 +1,142 @@ +package github + +import ( + "context" + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestAdminService_GetAdminStats(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/enterprise/stats/all", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + + fmt.Fprint(w, ` +{ + "repos": { + "total_repos": 212, + "root_repos": 194, + "fork_repos": 18, + "org_repos": 51, + "total_pushes": 3082, + "total_wikis": 15 + }, + "hooks": { + "total_hooks": 27, + "active_hooks": 23, + "inactive_hooks": 4 + }, + "pages": { + "total_pages": 36 + }, + "orgs": { + "total_orgs": 33, + "disabled_orgs": 0, + "total_teams": 60, + "total_team_members": 314 + }, + "users": { + "total_users": 254, + "admin_users": 45, + "suspended_users": 21 + }, + "pulls": { + "total_pulls": 86, + "merged_pulls": 60, + "mergeable_pulls": 21, + "unmergeable_pulls": 3 + }, + "issues": { + "total_issues": 179, + "open_issues": 83, + "closed_issues": 96 + }, + "milestones": { + "total_milestones": 7, + "open_milestones": 6, + "closed_milestones": 1 + }, + "gists": { + "total_gists": 178, + "private_gists": 151, + "public_gists": 25 + }, + "comments": { + "total_commit_comments": 6, + "total_gist_comments": 28, + "total_issue_comments": 366, + "total_pull_request_comments": 30 + } +} +`) + }) + + stats, _, err := client.Admin.GetAdminStats(context.Background()) + if err != nil { + t.Errorf("AdminService.GetAdminStats returned error: %v", err) + } + + want := &AdminStats{ + Repos: &RepoStats{ + TotalRepos: Int(212), + RootRepos: Int(194), + ForkRepos: Int(18), + OrgRepos: Int(51), + TotalPushes: Int(3082), + TotalWikis: Int(15), + }, + Hooks: &HookStats{ + TotalHooks: Int(27), + ActiveHooks: Int(23), + InactiveHooks: Int(4), + }, + Pages: &PageStats{ + TotalPages: Int(36), + }, + Orgs: &OrgStats{ + TotalOrgs: Int(33), + DisabledOrgs: Int(0), + TotalTeams: Int(60), + TotalTeamMembers: Int(314), + }, + Users: &UserStats{ + TotalUsers: Int(254), + AdminUsers: Int(45), + SuspendedUsers: Int(21), + }, + Pulls: &PullStats{ + TotalPulls: Int(86), + MergedPulls: Int(60), + MergablePulls: Int(21), + UnmergablePulls: Int(3), + }, + Issues: &IssueStats{ + TotalIssues: Int(179), + OpenIssues: Int(83), + ClosedIssues: Int(96), + }, + Milestones: &MilestoneStats{ + TotalMilestones: Int(7), + OpenMilestones: Int(6), + ClosedMilestones: Int(1), + }, + Gists: &GistStats{ + TotalGists: Int(178), + PrivateGists: Int(151), + PublicGists: Int(25), + }, + Comments: &CommentStats{ + TotalCommitComments: Int(6), + TotalGistComments: Int(28), + TotalIssueComments: Int(366), + TotalPullRequestComments: Int(30), + }, + } + if !reflect.DeepEqual(stats, want) { + t.Errorf("AdminService.GetAdminStats returned %+v, want %+v", stats, want) + } +} diff --git a/vendor/github.com/google/go-github/github/admin_test.go b/vendor/github.com/google/go-github/github/admin_test.go index 32a870eb4..8979686f1 100644 --- a/vendor/github.com/google/go-github/github/admin_test.go +++ b/vendor/github.com/google/go-github/github/admin_test.go @@ -15,7 +15,7 @@ import ( ) func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &UserLDAPMapping{ @@ -39,7 +39,7 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { } want := &UserLDAPMapping{ - ID: Int(1), + ID: Int64(1), LDAPDN: String("uid=asdf,ou=users,dc=github,dc=com"), } if !reflect.DeepEqual(mapping, want) { @@ -48,7 +48,7 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { } func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &TeamLDAPMapping{ @@ -72,7 +72,7 @@ func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) { } want := &TeamLDAPMapping{ - ID: Int(1), + ID: Int64(1), LDAPDN: String("cn=Enterprise Ops,ou=teams,dc=github,dc=com"), } if !reflect.DeepEqual(mapping, want) { diff --git a/vendor/github.com/google/go-github/github/apps.go b/vendor/github.com/google/go-github/github/apps.go index ff3389382..ae3aabda3 100644 --- a/vendor/github.com/google/go-github/github/apps.go +++ b/vendor/github.com/google/go-github/github/apps.go @@ -5,7 +5,11 @@ package github -import "context" +import ( + "context" + "fmt" + "time" +) // AppsService provides access to the installation related functions // in the GitHub API. @@ -13,6 +17,88 @@ import "context" // GitHub API docs: https://developer.github.com/v3/apps/ type AppsService service +// App represents a GitHub App. +type App struct { + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Owner *User `json:"owner,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + ExternalURL *string `json:"external_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` +} + +// InstallationToken represents an installation token. +type InstallationToken struct { + Token *string `json:"token,omitempty"` + ExpiresAt *time.Time `json:"expires_at,omitempty"` +} + +// InstallationPermissions lists the permissions for metadata, contents, issues and single file for an installation. +type InstallationPermissions struct { + Metadata *string `json:"metadata,omitempty"` + Contents *string `json:"contents,omitempty"` + Issues *string `json:"issues,omitempty"` + SingleFile *string `json:"single_file,omitempty"` +} + +// Installation represents a GitHub Apps installation. +type Installation struct { + ID *int64 `json:"id,omitempty"` + AppID *int64 `json:"app_id,omitempty"` + TargetID *int64 `json:"target_id,omitempty"` + Account *User `json:"account,omitempty"` + AccessTokensURL *string `json:"access_tokens_url,omitempty"` + RepositoriesURL *string `json:"repositories_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + TargetType *string `json:"target_type,omitempty"` + SingleFileName *string `json:"single_file_name,omitempty"` + RepositorySelection *string `json:"repository_selection,omitempty"` + Events []string `json:"events,omitempty"` + Permissions *InstallationPermissions `json:"permissions,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` +} + +func (i Installation) String() string { + return Stringify(i) +} + +// Get a single GitHub App. Passing the empty string will get +// the authenticated GitHub App. +// +// Note: appSlug is just the URL-friendly name of your GitHub App. +// You can find this on the settings page for your GitHub App +// (e.g., https://github.com/settings/apps/:app_slug). +// +// GitHub API docs: https://developer.github.com/v3/apps/#get-a-single-github-app +func (s *AppsService) Get(ctx context.Context, appSlug string) (*App, *Response, error) { + var u string + if appSlug != "" { + u = fmt.Sprintf("apps/%v", appSlug) + } else { + u = "app" + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + app := new(App) + resp, err := s.client.Do(ctx, req, app) + if err != nil { + return nil, resp, err + } + + return app, resp, nil +} + // ListInstallations lists the installations that the current GitHub App has. // // GitHub API docs: https://developer.github.com/v3/apps/#find-installations @@ -38,3 +124,107 @@ func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ( return i, resp, nil } + +// GetInstallation returns the specified installation. +// +// GitHub API docs: https://developer.github.com/v3/apps/#get-a-single-installation +func (s *AppsService) GetInstallation(ctx context.Context, id int64) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("app/installations/%v", id)) +} + +// ListUserInstallations lists installations that are accessible to the authenticated user. +// +// GitHub API docs: https://developer.github.com/v3/apps/#list-installations-for-user +func (s *AppsService) ListUserInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) { + u, err := addOptions("user/installations", opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + var i struct { + Installations []*Installation `json:"installations"` + } + resp, err := s.client.Do(ctx, req, &i) + if err != nil { + return nil, resp, err + } + + return i.Installations, resp, nil +} + +// CreateInstallationToken creates a new installation token. +// +// GitHub API docs: https://developer.github.com/v3/apps/#create-a-new-installation-token +func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64) (*InstallationToken, *Response, error) { + u := fmt.Sprintf("app/installations/%v/access_tokens", id) + + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + t := new(InstallationToken) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// FindOrganizationInstallation finds the organization's installation information. +// +// GitHub API docs: https://developer.github.com/v3/apps/#find-organization-installation +func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org string) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org)) +} + +// FindRepositoryInstallation finds the repository's installation information. +// +// GitHub API docs: https://developer.github.com/v3/apps/#find-repository-installation +func (s *AppsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("repos/%v/%v/installation", owner, repo)) +} + +// FindRepositoryInstallationByID finds the repository's installation information. +// +// Note: FindRepositoryInstallationByID uses the undocumented GitHub API endpoint /repositories/:id/installation. +func (s *AppsService) FindRepositoryInstallationByID(ctx context.Context, id int64) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("repositories/%d/installation", id)) +} + +// FindUserInstallation finds the user's installation information. +// +// GitHub API docs: https://developer.github.com/v3/apps/#find-repository-installation +func (s *AppsService) FindUserInstallation(ctx context.Context, user string) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("users/%v/installation", user)) +} + +func (s *AppsService) getInstallation(ctx context.Context, url string) (*Installation, *Response, error) { + req, err := s.client.NewRequest("GET", url, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + i := new(Installation) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + + return i, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/apps_installation.go b/vendor/github.com/google/go-github/github/apps_installation.go index 6a2779953..ccfecb8d8 100644 --- a/vendor/github.com/google/go-github/github/apps_installation.go +++ b/vendor/github.com/google/go-github/github/apps_installation.go @@ -5,20 +5,10 @@ package github -import "context" - -// Installation represents a GitHub Apps installation. -type Installation struct { - ID *int `json:"id,omitempty"` - Account *User `json:"account,omitempty"` - AccessTokensURL *string `json:"access_tokens_url,omitempty"` - RepositoriesURL *string `json:"repositories_url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` -} - -func (i Installation) String() string { - return Stringify(i) -} +import ( + "context" + "fmt" +) // ListRepos lists the repositories that are accessible to the authenticated installation. // @@ -47,3 +37,65 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos return r.Repositories, resp, nil } + +// ListUserRepos lists repositories that are accessible +// to the authenticated user for an installation. +// +// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation +func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opt *ListOptions) ([]*Repository, *Response, error) { + u := fmt.Sprintf("user/installations/%v/repositories", id) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + var r struct { + Repositories []*Repository `json:"repositories"` + } + resp, err := s.client.Do(ctx, req, &r) + if err != nil { + return nil, resp, err + } + + return r.Repositories, resp, nil +} + +// AddRepository adds a single repository to an installation. +// +// GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation +func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int64) (*Repository, *Response, error) { + u := fmt.Sprintf("apps/installations/%v/repositories/%v", instID, repoID) + req, err := s.client.NewRequest("PUT", u, nil) + if err != nil { + return nil, nil, err + } + + r := new(Repository) + resp, err := s.client.Do(ctx, req, r) + if err != nil { + return nil, resp, err + } + + return r, resp, nil +} + +// RemoveRepository removes a single repository from an installation. +// +// GitHub docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation +func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int64) (*Response, error) { + u := fmt.Sprintf("apps/installations/%v/repositories/%v", instID, repoID) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/apps_installation_test.go b/vendor/github.com/google/go-github/github/apps_installation_test.go index 462d15a3f..01358c00e 100644 --- a/vendor/github.com/google/go-github/github/apps_installation_test.go +++ b/vendor/github.com/google/go-github/github/apps_installation_test.go @@ -14,7 +14,7 @@ import ( ) func TestAppsService_ListRepos(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/installation/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -33,8 +33,69 @@ func TestAppsService_ListRepos(t *testing.T) { t.Errorf("Apps.ListRepos returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(repositories, want) { t.Errorf("Apps.ListRepos returned %+v, want %+v", repositories, want) } } + +func TestAppsService_ListUserRepos(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/installations/1/repositories", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + testFormValues(t, r, values{ + "page": "1", + "per_page": "2", + }) + fmt.Fprint(w, `{"repositories": [{"id":1}]}`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + repositories, _, err := client.Apps.ListUserRepos(context.Background(), 1, opt) + if err != nil { + t.Errorf("Apps.ListUserRepos returned error: %v", err) + } + + want := []*Repository{{ID: Int64(1)}} + if !reflect.DeepEqual(repositories, want) { + t.Errorf("Apps.ListUserRepos returned %+v, want %+v", repositories, want) + } +} + +func TestAppsService_AddRepository(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) + }) + + repo, _, err := client.Apps.AddRepository(context.Background(), 1, 1) + if err != nil { + t.Errorf("Apps.AddRepository returned error: %v", err) + } + + want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} + if !reflect.DeepEqual(repo, want) { + t.Errorf("AddRepository returned %+v, want %+v", repo, want) + } +} + +func TestAppsService_RemoveRepository(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Apps.RemoveRepository(context.Background(), 1, 1) + if err != nil { + t.Errorf("Apps.RemoveRepository returned error: %v", err) + } +} diff --git a/vendor/github.com/google/go-github/github/apps_marketplace.go b/vendor/github.com/google/go-github/github/apps_marketplace.go new file mode 100644 index 000000000..6dd568a2d --- /dev/null +++ b/vendor/github.com/google/go-github/github/apps_marketplace.go @@ -0,0 +1,183 @@ +// Copyright 2017 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// MarketplaceService handles communication with the marketplace related +// methods of the GitHub API. +// +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/ +type MarketplaceService struct { + client *Client + // Stubbed controls whether endpoints that return stubbed data are used + // instead of production endpoints. Stubbed data is fake data that's useful + // for testing your GitHub Apps. Stubbed data is hard-coded and will not + // change based on actual subscriptions. + // + // GitHub API docs: https://developer.github.com/v3/apps/marketplace/ + Stubbed bool +} + +// MarketplacePlan represents a GitHub Apps Marketplace Listing Plan. +type MarketplacePlan struct { + URL *string `json:"url,omitempty"` + AccountsURL *string `json:"accounts_url,omitempty"` + ID *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"` + YearlyPriceInCents *int `json:"yearly_price_in_cents,omitempty"` + // The pricing model for this listing. Can be one of "flat-rate", "per-unit", or "free". + PriceModel *string `json:"price_model,omitempty"` + UnitName *string `json:"unit_name,omitempty"` + Bullets *[]string `json:"bullets,omitempty"` + // State can be one of the values "draft" or "published". + State *string `json:"state,omitempty"` + HasFreeTrial *bool `json:"has_free_trial,omitempty"` +} + +// MarketplacePurchase represents a GitHub Apps Marketplace Purchase. +type MarketplacePurchase struct { + // BillingCycle can be one of the values "yearly", "monthly" or nil. + BillingCycle *string `json:"billing_cycle,omitempty"` + NextBillingDate *Timestamp `json:"next_billing_date,omitempty"` + UnitCount *int `json:"unit_count,omitempty"` + Plan *MarketplacePlan `json:"plan,omitempty"` + Account *MarketplacePlanAccount `json:"account,omitempty"` + OnFreeTrial *bool `json:"on_free_trial,omitempty"` + FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"` +} + +// MarketplacePendingChange represents a pending change to a GitHub Apps Marketplace Plan. +type MarketplacePendingChange struct { + EffectiveDate *Timestamp `json:"effective_date,omitempty"` + UnitCount *int `json:"unit_count,omitempty"` + ID *int64 `json:"id,omitempty"` + Plan *MarketplacePlan `json:"plan,omitempty"` +} + +// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan. +type MarketplacePlanAccount struct { + URL *string `json:"url,omitempty"` + Type *string `json:"type,omitempty"` + ID *int64 `json:"id,omitempty"` + Login *string `json:"login,omitempty"` + Email *string `json:"email,omitempty"` + OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"` + MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"` + MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"` +} + +// ListPlans lists all plans for your Marketplace listing. +// +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-plans-for-your-marketplace-listing +func (s *MarketplaceService) ListPlans(ctx context.Context, opt *ListOptions) ([]*MarketplacePlan, *Response, error) { + uri := s.marketplaceURI("plans") + u, err := addOptions(uri, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var plans []*MarketplacePlan + resp, err := s.client.Do(ctx, req, &plans) + if err != nil { + return nil, resp, err + } + + return plans, resp, nil +} + +// ListPlanAccountsForPlan lists all GitHub accounts (user or organization) on a specific plan. +// +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-github-accounts-user-or-organization-on-a-specific-plan +func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) { + uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID)) + u, err := addOptions(uri, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var accounts []*MarketplacePlanAccount + resp, err := s.client.Do(ctx, req, &accounts) + if err != nil { + return nil, resp, err + } + + return accounts, resp, nil +} + +// ListPlanAccountsForAccount lists all GitHub accounts (user or organization) associated with an account. +// +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#check-if-a-github-account-is-associated-with-any-marketplace-listing +func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, accountID int64, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) { + uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID)) + u, err := addOptions(uri, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var accounts []*MarketplacePlanAccount + resp, err := s.client.Do(ctx, req, &accounts) + if err != nil { + return nil, resp, err + } + + return accounts, resp, nil +} + +// ListMarketplacePurchasesForUser lists all GitHub marketplace purchases made by a user. +// +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#get-a-users-marketplace-purchases +func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opt *ListOptions) ([]*MarketplacePurchase, *Response, error) { + uri := "user/marketplace_purchases" + if s.Stubbed { + uri = "user/marketplace_purchases/stubbed" + } + + u, err := addOptions(uri, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var purchases []*MarketplacePurchase + resp, err := s.client.Do(ctx, req, &purchases) + if err != nil { + return nil, resp, err + } + return purchases, resp, nil +} + +func (s *MarketplaceService) marketplaceURI(endpoint string) string { + url := "marketplace_listing" + if s.Stubbed { + url = "marketplace_listing/stubbed" + } + return url + "/" + endpoint +} diff --git a/vendor/github.com/google/go-github/github/apps_marketplace_test.go b/vendor/github.com/google/go-github/github/apps_marketplace_test.go new file mode 100644 index 000000000..e293c83a1 --- /dev/null +++ b/vendor/github.com/google/go-github/github/apps_marketplace_test.go @@ -0,0 +1,194 @@ +// Copyright 2017 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestMarketplaceService_ListPlans(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "page": "1", + "per_page": "2", + }) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = false + plans, _, err := client.Marketplace.ListPlans(context.Background(), opt) + if err != nil { + t.Errorf("Marketplace.ListPlans returned error: %v", err) + } + + want := []*MarketplacePlan{{ID: Int64(1)}} + if !reflect.DeepEqual(plans, want) { + t.Errorf("Marketplace.ListPlans returned %+v, want %+v", plans, want) + } +} + +func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = true + plans, _, err := client.Marketplace.ListPlans(context.Background(), opt) + if err != nil { + t.Errorf("Marketplace.ListPlans (Stubbed) returned error: %v", err) + } + + want := []*MarketplacePlan{{ID: Int64(1)}} + if !reflect.DeepEqual(plans, want) { + t.Errorf("Marketplace.ListPlans (Stubbed) returned %+v, want %+v", plans, want) + } +} + +func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = false + accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt) + if err != nil { + t.Errorf("Marketplace.ListPlanAccountsForPlan returned error: %v", err) + } + + want := []*MarketplacePlanAccount{{ID: Int64(1)}} + if !reflect.DeepEqual(accounts, want) { + t.Errorf("Marketplace.ListPlanAccountsForPlan returned %+v, want %+v", accounts, want) + } +} + +func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/stubbed/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = true + accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt) + if err != nil { + t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned error: %v", err) + } + + want := []*MarketplacePlanAccount{{ID: Int64(1)}} + if !reflect.DeepEqual(accounts, want) { + t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned %+v, want %+v", accounts, want) + } +} + +func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1, "marketplace_pending_change": {"id": 77}}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = false + accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt) + if err != nil { + t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err) + } + + want := []*MarketplacePlanAccount{{ID: Int64(1), MarketplacePendingChange: &MarketplacePendingChange{ID: Int64(77)}}} + if !reflect.DeepEqual(accounts, want) { + t.Errorf("Marketplace.ListPlanAccountsForAccount returned %+v, want %+v", accounts, want) + } +} + +func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/marketplace_listing/stubbed/accounts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = true + accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt) + if err != nil { + t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned error: %v", err) + } + + want := []*MarketplacePlanAccount{{ID: Int64(1)}} + if !reflect.DeepEqual(accounts, want) { + t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned %+v, want %+v", accounts, want) + } +} + +func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = false + purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt) + if err != nil { + t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err) + } + + want := []*MarketplacePurchase{{BillingCycle: String("monthly")}} + if !reflect.DeepEqual(purchases, want) { + t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want) + } +} + +func TestMarketplaceService_Stubbed_ListMarketplacePurchasesForUser(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/marketplace_purchases/stubbed", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + client.Marketplace.Stubbed = true + purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt) + if err != nil { + t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err) + } + + want := []*MarketplacePurchase{{BillingCycle: String("monthly")}} + if !reflect.DeepEqual(purchases, want) { + t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want) + } +} diff --git a/vendor/github.com/google/go-github/github/apps_test.go b/vendor/github.com/google/go-github/github/apps_test.go index f847b8427..a594eab31 100644 --- a/vendor/github.com/google/go-github/github/apps_test.go +++ b/vendor/github.com/google/go-github/github/apps_test.go @@ -11,10 +11,53 @@ import ( "net/http" "reflect" "testing" + "time" ) +func TestAppsService_Get_authenticatedApp(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1}`) + }) + + app, _, err := client.Apps.Get(context.Background(), "") + if err != nil { + t.Errorf("Apps.Get returned error: %v", err) + } + + want := &App{ID: Int64(1)} + if !reflect.DeepEqual(app, want) { + t.Errorf("Apps.Get returned %+v, want %+v", app, want) + } +} + +func TestAppsService_Get_specifiedApp(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/apps/a", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"html_url":"https://github.com/apps/a"}`) + }) + + app, _, err := client.Apps.Get(context.Background(), "a") + if err != nil { + t.Errorf("Apps.Get returned error: %v", err) + } + + want := &App{HTMLURL: String("https://github.com/apps/a")} + if !reflect.DeepEqual(app, want) { + t.Errorf("Apps.Get returned %+v, want %+v", *app.HTMLURL, *want.HTMLURL) + } +} + func TestAppsService_ListInstallations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/app/installations", func(w http.ResponseWriter, r *http.Request) { @@ -24,7 +67,26 @@ func TestAppsService_ListInstallations(t *testing.T) { "page": "1", "per_page": "2", }) - fmt.Fprint(w, `[{"id":1}]`) + fmt.Fprint(w, `[{ + "id":1, + "app_id":1, + "target_id":1, + "target_type": "Organization", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write", + "single_file": "write" + }, + "events": [ + "push", + "pull_request" + ], + "single_file_name": "config.yml", + "repository_selection": "selected", + "created_at": "2018-01-01T00:00:00Z", + "updated_at": "2018-01-01T00:00:00Z"}]`, + ) }) opt := &ListOptions{Page: 1, PerPage: 2} @@ -33,8 +95,176 @@ func TestAppsService_ListInstallations(t *testing.T) { t.Errorf("Apps.ListInstallations returned error: %v", err) } - want := []*Installation{{ID: Int(1)}} + date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} + want := []*Installation{{ + ID: Int64(1), + AppID: Int64(1), + TargetID: Int64(1), + TargetType: String("Organization"), + SingleFileName: String("config.yml"), + RepositorySelection: String("selected"), + Permissions: &InstallationPermissions{ + Metadata: String("read"), + Contents: String("read"), + Issues: String("write"), + SingleFile: String("write")}, + Events: []string{"push", "pull_request"}, + CreatedAt: &date, + UpdatedAt: &date, + }} if !reflect.DeepEqual(installations, want) { t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want) } } + +func TestAppsService_GetInstallation(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/app/installations/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}`) + }) + + installation, _, err := client.Apps.GetInstallation(context.Background(), 1) + if err != nil { + t.Errorf("Apps.GetInstallation returned error: %v", err) + } + + want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")} + if !reflect.DeepEqual(installation, want) { + t.Errorf("Apps.GetInstallation returned %+v, want %+v", installation, want) + } +} + +func TestAppsService_ListUserInstallations(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/installations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + testFormValues(t, r, values{ + "page": "1", + "per_page": "2", + }) + fmt.Fprint(w, `{"installations":[{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}]}`) + }) + + opt := &ListOptions{Page: 1, PerPage: 2} + installations, _, err := client.Apps.ListUserInstallations(context.Background(), opt) + if err != nil { + t.Errorf("Apps.ListUserInstallations returned error: %v", err) + } + + want := []*Installation{{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")}} + if !reflect.DeepEqual(installations, want) { + t.Errorf("Apps.ListUserInstallations returned %+v, want %+v", installations, want) + } +} + +func TestAppsService_CreateInstallationToken(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/app/installations/1/access_tokens", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"token":"t"}`) + }) + + token, _, err := client.Apps.CreateInstallationToken(context.Background(), 1) + if err != nil { + t.Errorf("Apps.CreateInstallationToken returned error: %v", err) + } + + want := &InstallationToken{Token: String("t")} + if !reflect.DeepEqual(token, want) { + t.Errorf("Apps.CreateInstallationToken returned %+v, want %+v", token, want) + } +} + +func TestAppsService_FindOrganizationInstallation(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/orgs/o/installation", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}`) + }) + + installation, _, err := client.Apps.FindOrganizationInstallation(context.Background(), "o") + if err != nil { + t.Errorf("Apps.FindOrganizationInstallation returned error: %v", err) + } + + want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")} + if !reflect.DeepEqual(installation, want) { + t.Errorf("Apps.FindOrganizationInstallation returned %+v, want %+v", installation, want) + } +} + +func TestAppsService_FindRepositoryInstallation(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/installation", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}`) + }) + + installation, _, err := client.Apps.FindRepositoryInstallation(context.Background(), "o", "r") + if err != nil { + t.Errorf("Apps.FindRepositoryInstallation returned error: %v", err) + } + + want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")} + if !reflect.DeepEqual(installation, want) { + t.Errorf("Apps.FindRepositoryInstallation returned %+v, want %+v", installation, want) + } +} + +func TestAppsService_FindRepositoryInstallationByID(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repositories/1/installation", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}`) + }) + + installation, _, err := client.Apps.FindRepositoryInstallationByID(context.Background(), 1) + if err != nil { + t.Errorf("Apps.FindRepositoryInstallationByID returned error: %v", err) + } + + want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")} + if !reflect.DeepEqual(installation, want) { + t.Errorf("Apps.FindRepositoryInstallationByID returned %+v, want %+v", installation, want) + } +} + +func TestAppsService_FindUserInstallation(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/users/u/installation", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "User"}`) + }) + + installation, _, err := client.Apps.FindUserInstallation(context.Background(), "u") + if err != nil { + t.Errorf("Apps.FindUserInstallation returned error: %v", err) + } + + want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("User")} + if !reflect.DeepEqual(installation, want) { + t.Errorf("Apps.FindUserInstallation returned %+v, want %+v", installation, want) + } +} diff --git a/vendor/github.com/google/go-github/github/authorizations.go b/vendor/github.com/google/go-github/github/authorizations.go index 638745ac1..190205b02 100644 --- a/vendor/github.com/google/go-github/github/authorizations.go +++ b/vendor/github.com/google/go-github/github/authorizations.go @@ -54,7 +54,7 @@ type AuthorizationsService service // Authorization represents an individual GitHub authorization. type Authorization struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` Scopes []Scope `json:"scopes,omitempty"` Token *string `json:"token,omitempty"` @@ -88,7 +88,7 @@ func (a AuthorizationApp) String() string { // Grant represents an OAuth application that has been granted access to an account. type Grant struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` App *AuthorizationApp `json:"app,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` @@ -160,7 +160,7 @@ func (s *AuthorizationsService) List(ctx context.Context, opt *ListOptions) ([]* // Get a single authorization. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization -func (s *AuthorizationsService) Get(ctx context.Context, id int) (*Authorization, *Response, error) { +func (s *AuthorizationsService) Get(ctx context.Context, id int64) (*Authorization, *Response, error) { u := fmt.Sprintf("authorizations/%d", id) req, err := s.client.NewRequest("GET", u, nil) @@ -234,7 +234,7 @@ func (s *AuthorizationsService) GetOrCreateForApp(ctx context.Context, clientID // Edit a single authorization. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization -func (s *AuthorizationsService) Edit(ctx context.Context, id int, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) { +func (s *AuthorizationsService) Edit(ctx context.Context, id int64, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) { u := fmt.Sprintf("authorizations/%d", id) req, err := s.client.NewRequest("PATCH", u, auth) @@ -254,7 +254,7 @@ func (s *AuthorizationsService) Edit(ctx context.Context, id int, auth *Authoriz // Delete a single authorization. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization -func (s *AuthorizationsService) Delete(ctx context.Context, id int) (*Response, error) { +func (s *AuthorizationsService) Delete(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("authorizations/%d", id) req, err := s.client.NewRequest("DELETE", u, nil) @@ -366,7 +366,7 @@ func (s *AuthorizationsService) ListGrants(ctx context.Context, opt *ListOptions // GetGrant gets a single OAuth application grant. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-grant -func (s *AuthorizationsService) GetGrant(ctx context.Context, id int) (*Grant, *Response, error) { +func (s *AuthorizationsService) GetGrant(ctx context.Context, id int64) (*Grant, *Response, error) { u := fmt.Sprintf("applications/grants/%d", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -387,7 +387,7 @@ func (s *AuthorizationsService) GetGrant(ctx context.Context, id int) (*Grant, * // the user. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-a-grant -func (s *AuthorizationsService) DeleteGrant(ctx context.Context, id int) (*Response, error) { +func (s *AuthorizationsService) DeleteGrant(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("applications/grants/%d", id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/authorizations_test.go b/vendor/github.com/google/go-github/github/authorizations_test.go index 61bf21252..faf25749c 100644 --- a/vendor/github.com/google/go-github/github/authorizations_test.go +++ b/vendor/github.com/google/go-github/github/authorizations_test.go @@ -15,7 +15,7 @@ import ( ) func TestAuthorizationsService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) { @@ -30,14 +30,14 @@ func TestAuthorizationsService_List(t *testing.T) { t.Errorf("Authorizations.List returned error: %v", err) } - want := []*Authorization{{ID: Int(1)}} + want := []*Authorization{{ID: Int64(1)}} if !reflect.DeepEqual(got, want) { t.Errorf("Authorizations.List returned %+v, want %+v", *got[0].ID, *want[0].ID) } } func TestAuthorizationsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -50,14 +50,14 @@ func TestAuthorizationsService_Get(t *testing.T) { t.Errorf("Authorizations.Get returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorizations.Get returned auth %+v, want %+v", got, want) } } func TestAuthorizationsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -81,14 +81,14 @@ func TestAuthorizationsService_Create(t *testing.T) { t.Errorf("Authorizations.Create returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorization.Create returned %+v, want %+v", got, want) } } func TestAuthorizationsService_GetOrCreateForApp(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -112,14 +112,14 @@ func TestAuthorizationsService_GetOrCreateForApp(t *testing.T) { t.Errorf("Authorizations.GetOrCreateForApp returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorization.GetOrCreateForApp returned %+v, want %+v", got, want) } } func TestAuthorizationsService_GetOrCreateForApp_Fingerprint(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -144,14 +144,14 @@ func TestAuthorizationsService_GetOrCreateForApp_Fingerprint(t *testing.T) { t.Errorf("Authorizations.GetOrCreateForApp returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorization.GetOrCreateForApp returned %+v, want %+v", got, want) } } func TestAuthorizationsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationUpdateRequest{ @@ -175,14 +175,14 @@ func TestAuthorizationsService_Edit(t *testing.T) { t.Errorf("Authorizations.Edit returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorization.Update returned %+v, want %+v", got, want) } } func TestAuthorizationsService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -197,7 +197,7 @@ func TestAuthorizationsService_Delete(t *testing.T) { } func TestAuthorizationsService_Check(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -210,14 +210,14 @@ func TestAuthorizationsService_Check(t *testing.T) { t.Errorf("Authorizations.Check returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorizations.Check returned auth %+v, want %+v", got, want) } } func TestAuthorizationsService_Reset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -230,14 +230,14 @@ func TestAuthorizationsService_Reset(t *testing.T) { t.Errorf("Authorizations.Reset returned error: %v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorizations.Reset returned auth %+v, want %+v", got, want) } } func TestAuthorizationsService_Revoke(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -252,7 +252,7 @@ func TestAuthorizationsService_Revoke(t *testing.T) { } func TestListGrants(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants", func(w http.ResponseWriter, r *http.Request) { @@ -265,14 +265,14 @@ func TestListGrants(t *testing.T) { t.Errorf("OAuthAuthorizations.ListGrants returned error: %v", err) } - want := []*Grant{{ID: Int(1)}} + want := []*Grant{{ID: Int64(1)}} if !reflect.DeepEqual(got, want) { t.Errorf("OAuthAuthorizations.ListGrants = %+v, want %+v", got, want) } } func TestListGrants_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants", func(w http.ResponseWriter, r *http.Request) { @@ -290,7 +290,7 @@ func TestListGrants_withOptions(t *testing.T) { } func TestGetGrant(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants/1", func(w http.ResponseWriter, r *http.Request) { @@ -303,14 +303,14 @@ func TestGetGrant(t *testing.T) { t.Errorf("OAuthAuthorizations.GetGrant returned error: %v", err) } - want := &Grant{ID: Int(1)} + want := &Grant{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("OAuthAuthorizations.GetGrant = %+v, want %+v", got, want) } } func TestDeleteGrant(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants/1", func(w http.ResponseWriter, r *http.Request) { @@ -324,7 +324,7 @@ func TestDeleteGrant(t *testing.T) { } func TestAuthorizationsService_CreateImpersonation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { @@ -338,14 +338,14 @@ func TestAuthorizationsService_CreateImpersonation(t *testing.T) { t.Errorf("Authorizations.CreateImpersonation returned error: %+v", err) } - want := &Authorization{ID: Int(1)} + want := &Authorization{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Authorizations.CreateImpersonation returned %+v, want %+v", *got.ID, *want.ID) } } func TestAuthorizationsService_DeleteImpersonation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/checks.go b/vendor/github.com/google/go-github/github/checks.go new file mode 100644 index 000000000..f27d40d4d --- /dev/null +++ b/vendor/github.com/google/go-github/github/checks.go @@ -0,0 +1,431 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// ChecksService provides access to the Checks API in the +// GitHub API. +// +// GitHub API docs: https://developer.github.com/v3/checks/ +type ChecksService service + +// CheckRun represents a GitHub check run on a repository associated with a GitHub app. +type CheckRun struct { + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + HeadSHA *string `json:"head_sha,omitempty"` + ExternalID *string `json:"external_id,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + DetailsURL *string `json:"details_url,omitempty"` + Status *string `json:"status,omitempty"` + Conclusion *string `json:"conclusion,omitempty"` + StartedAt *Timestamp `json:"started_at,omitempty"` + CompletedAt *Timestamp `json:"completed_at,omitempty"` + Output *CheckRunOutput `json:"output,omitempty"` + Name *string `json:"name,omitempty"` + CheckSuite *CheckSuite `json:"check_suite,omitempty"` + App *App `json:"app,omitempty"` + PullRequests []*PullRequest `json:"pull_requests,omitempty"` +} + +// CheckRunOutput represents the output of a CheckRun. +type CheckRunOutput struct { + Title *string `json:"title,omitempty"` + Summary *string `json:"summary,omitempty"` + Text *string `json:"text,omitempty"` + AnnotationsCount *int `json:"annotations_count,omitempty"` + AnnotationsURL *string `json:"annotations_url,omitempty"` + Annotations []*CheckRunAnnotation `json:"annotations,omitempty"` + Images []*CheckRunImage `json:"images,omitempty"` +} + +// CheckRunAnnotation represents an annotation object for a CheckRun output. +type CheckRunAnnotation struct { + Path *string `json:"path,omitempty"` + BlobHRef *string `json:"blob_href,omitempty"` + StartLine *int `json:"start_line,omitempty"` + EndLine *int `json:"end_line,omitempty"` + AnnotationLevel *string `json:"annotation_level,omitempty"` + Message *string `json:"message,omitempty"` + Title *string `json:"title,omitempty"` + RawDetails *string `json:"raw_details,omitempty"` +} + +// CheckRunImage represents an image object for a CheckRun output. +type CheckRunImage struct { + Alt *string `json:"alt,omitempty"` + ImageURL *string `json:"image_url,omitempty"` + Caption *string `json:"caption,omitempty"` +} + +// CheckSuite represents a suite of check runs. +type CheckSuite struct { + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + HeadBranch *string `json:"head_branch,omitempty"` + HeadSHA *string `json:"head_sha,omitempty"` + URL *string `json:"url,omitempty"` + BeforeSHA *string `json:"before,omitempty"` + AfterSHA *string `json:"after,omitempty"` + Status *string `json:"status,omitempty"` + Conclusion *string `json:"conclusion,omitempty"` + App *App `json:"app,omitempty"` + Repository *Repository `json:"repository,omitempty"` + PullRequests []*PullRequest `json:"pull_requests,omitempty"` +} + +func (c CheckRun) String() string { + return Stringify(c) +} + +func (c CheckSuite) String() string { + return Stringify(c) +} + +// GetCheckRun gets a check-run for a repository. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#get-a-single-check-run +func (s *ChecksService) GetCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*CheckRun, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + checkRun := new(CheckRun) + resp, err := s.client.Do(ctx, req, checkRun) + if err != nil { + return nil, resp, err + } + + return checkRun, resp, nil +} + +// GetCheckSuite gets a single check suite. +// +// GitHub API docs: https://developer.github.com/v3/checks/suites/#get-a-single-check-suite +func (s *ChecksService) GetCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*CheckSuite, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-suites/%v", owner, repo, checkSuiteID) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + checkSuite := new(CheckSuite) + resp, err := s.client.Do(ctx, req, checkSuite) + if err != nil { + return nil, resp, err + } + + return checkSuite, resp, nil +} + +// CreateCheckRunOptions sets up parameters needed to create a CheckRun. +type CreateCheckRunOptions struct { + Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.) + HeadBranch string `json:"head_branch"` // The name of the branch to perform a check against. (Required.) + HeadSHA string `json:"head_sha"` // The SHA of the commit. (Required.) + DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.) + ExternalID *string `json:"external_id,omitempty"` // A reference for the run on the integrator's system. (Optional.) + Status *string `json:"status,omitempty"` // The current status. Can be one of "queued", "in_progress", or "completed". Default: "queued". (Optional.) + Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".) + StartedAt *Timestamp `json:"started_at,omitempty"` // The time that the check run began. (Optional.) + CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.) + Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional) + Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.) +} + +// CheckRunAction exposes further actions the integrator can perform, which a user may trigger. +type CheckRunAction struct { + Label string `json:"label"` // The text to be displayed on a button in the web UI. The maximum size is 20 characters. (Required.) + Description string `json:"description"` // A short explanation of what this action would do. The maximum size is 40 characters. (Required.) + Identifier string `json:"identifier"` // A reference for the action on the integrator's system. The maximum size is 20 characters. (Required.) +} + +// CreateCheckRun creates a check run for repository. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#create-a-check-run +func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string, opt CreateCheckRunOptions) (*CheckRun, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-runs", owner, repo) + req, err := s.client.NewRequest("POST", u, opt) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + checkRun := new(CheckRun) + resp, err := s.client.Do(ctx, req, checkRun) + if err != nil { + return nil, resp, err + } + + return checkRun, resp, nil +} + +// UpdateCheckRunOptions sets up parameters needed to update a CheckRun. +type UpdateCheckRunOptions struct { + Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.) + HeadBranch *string `json:"head_branch,omitempty"` // The name of the branch to perform a check against. (Optional.) + HeadSHA *string `json:"head_sha,omitempty"` // The SHA of the commit. (Optional.) + DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.) + ExternalID *string `json:"external_id,omitempty"` // A reference for the run on the integrator's system. (Optional.) + Status *string `json:"status,omitempty"` // The current status. Can be one of "queued", "in_progress", or "completed". Default: "queued". (Optional.) + Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".) + CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.) + Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional) + Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.) +} + +// UpdateCheckRun updates a check run for a specific commit in a repository. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#update-a-check-run +func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string, checkRunID int64, opt UpdateCheckRunOptions) (*CheckRun, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID) + req, err := s.client.NewRequest("PATCH", u, opt) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + checkRun := new(CheckRun) + resp, err := s.client.Do(ctx, req, checkRun) + if err != nil { + return nil, resp, err + } + + return checkRun, resp, nil +} + +// ListCheckRunAnnotations lists the annotations for a check run. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-annotations-for-a-check-run +func (s *ChecksService) ListCheckRunAnnotations(ctx context.Context, owner, repo string, checkRunID int64, opt *ListOptions) ([]*CheckRunAnnotation, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-runs/%v/annotations", owner, repo, checkRunID) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + var checkRunAnnotations []*CheckRunAnnotation + resp, err := s.client.Do(ctx, req, &checkRunAnnotations) + if err != nil { + return nil, resp, err + } + + return checkRunAnnotations, resp, nil +} + +// ListCheckRunsOptions represents parameters to list check runs. +type ListCheckRunsOptions struct { + CheckName *string `url:"check_name,omitempty"` // Returns check runs with the specified name. + Status *string `url:"status,omitempty"` // Returns check runs with the specified status. Can be one of "queued", "in_progress", or "completed". + Filter *string `url:"filter,omitempty"` // Filters check runs by their completed_at timestamp. Can be one of "latest" (returning the most recent check runs) or "all". Default: "latest" + + ListOptions +} + +// ListCheckRunsResults represents the result of a check run list. +type ListCheckRunsResults struct { + Total *int `json:"total_count,omitempty"` + CheckRuns []*CheckRun `json:"check_runs,omitempty"` +} + +// ListCheckRunsForRef lists check runs for a specific ref. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref +func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, ref) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + var checkRunResults *ListCheckRunsResults + resp, err := s.client.Do(ctx, req, &checkRunResults) + if err != nil { + return nil, resp, err + } + + return checkRunResults, resp, nil +} + +// ListCheckRunsCheckSuite lists check runs for a check suite. +// +// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-in-a-check-suite +func (s *ChecksService) ListCheckRunsCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64, opt *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-suites/%v/check-runs", owner, repo, checkSuiteID) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + var checkRunResults *ListCheckRunsResults + resp, err := s.client.Do(ctx, req, &checkRunResults) + if err != nil { + return nil, resp, err + } + + return checkRunResults, resp, nil +} + +// ListCheckSuiteOptions represents parameters to list check suites. +type ListCheckSuiteOptions struct { + CheckName *string `url:"check_name,omitempty"` // Filters checks suites by the name of the check run. + AppID *int `url:"app_id,omitempty"` // Filters check suites by GitHub App id. + + ListOptions +} + +// ListCheckSuiteResults represents the result of a check run list. +type ListCheckSuiteResults struct { + Total *int `json:"total_count,omitempty"` + CheckSuites []*CheckSuite `json:"check_suites,omitempty"` +} + +// ListCheckSuitesForRef lists check suite for a specific ref. +// +// GitHub API docs: https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-specific-ref +func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckSuiteOptions) (*ListCheckSuiteResults, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, ref) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + var checkSuiteResults *ListCheckSuiteResults + resp, err := s.client.Do(ctx, req, &checkSuiteResults) + if err != nil { + return nil, resp, err + } + + return checkSuiteResults, resp, nil +} + +// AutoTriggerCheck enables or disables automatic creation of CheckSuite events upon pushes to the repository. +type AutoTriggerCheck struct { + AppID *int64 `json:"app_id,omitempty"` // The id of the GitHub App. (Required.) + Setting *bool `json:"setting,omitempty"` // Set to "true" to enable automatic creation of CheckSuite events upon pushes to the repository, or "false" to disable them. Default: "true" (Required.) +} + +// CheckSuitePreferenceOptions set options for check suite preferences for a repository. +type CheckSuitePreferenceOptions struct { + PreferenceList *PreferenceList `json:"auto_trigger_checks,omitempty"` // A list of auto trigger checks that can be set for a check suite in a repository. +} + +// CheckSuitePreferenceResults represents the results of the preference set operation. +type CheckSuitePreferenceResults struct { + Preferences *PreferenceList `json:"preferences,omitempty"` + Repository *Repository `json:"repository,omitempty"` +} + +// PreferenceList represents a list of auto trigger checks for repository +type PreferenceList struct { + AutoTriggerChecks []*AutoTriggerCheck `json:"auto_trigger_checks,omitempty"` // A slice of auto trigger checks that can be set for a check suite in a repository. +} + +// SetCheckSuitePreferences changes the default automatic flow when creating check suites. +// +// GitHub API docs: https://developer.github.com/v3/checks/suites/#set-preferences-for-check-suites-on-a-repository +func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, repo string, opt CheckSuitePreferenceOptions) (*CheckSuitePreferenceResults, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-suites/preferences", owner, repo) + req, err := s.client.NewRequest("PATCH", u, opt) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + var checkSuitePrefResults *CheckSuitePreferenceResults + resp, err := s.client.Do(ctx, req, &checkSuitePrefResults) + if err != nil { + return nil, resp, err + } + + return checkSuitePrefResults, resp, nil +} + +// CreateCheckSuiteOptions sets up parameters to manually create a check suites +type CreateCheckSuiteOptions struct { + HeadSHA string `json:"head_sha"` // The sha of the head commit. (Required.) + HeadBranch *string `json:"head_branch,omitempty"` // The name of the head branch where the code changes are implemented. +} + +// CreateCheckSuite manually creates a check suite for a repository. +// +// GitHub API docs: https://developer.github.com/v3/checks/suites/#create-a-check-suite +func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string, opt CreateCheckSuiteOptions) (*CheckSuite, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-suites", owner, repo) + req, err := s.client.NewRequest("POST", u, opt) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + checkSuite := new(CheckSuite) + resp, err := s.client.Do(ctx, req, checkSuite) + if err != nil { + return nil, resp, err + } + + return checkSuite, resp, nil +} + +// ReRequestCheckSuite triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. +// +// GitHub API docs: https://developer.github.com/v3/checks/suites/#rerequest-check-suite +func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-suites/%v/rerequest", owner, repo, checkSuiteID) + + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + resp, err := s.client.Do(ctx, req, nil) + return resp, err +} diff --git a/vendor/github.com/google/go-github/github/checks_test.go b/vendor/github.com/google/go-github/github/checks_test.go new file mode 100644 index 000000000..3170f70d4 --- /dev/null +++ b/vendor/github.com/google/go-github/github/checks_test.go @@ -0,0 +1,479 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" + "reflect" + "testing" + "time" +) + +func TestChecksService_GetCheckRun(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{ + "id": 1, + "name":"testCheckRun", + "status": "completed", + "conclusion": "neutral", + "started_at": "2018-05-04T01:14:52Z", + "completed_at": "2018-05-04T01:14:52Z"}`) + }) + checkRun, _, err := client.Checks.GetCheckRun(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("Checks.GetCheckRun return error: %v", err) + } + startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + completeAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + + want := &CheckRun{ + ID: Int64(1), + Status: String("completed"), + Conclusion: String("neutral"), + StartedAt: &Timestamp{startedAt}, + CompletedAt: &Timestamp{completeAt}, + Name: String("testCheckRun"), + } + if !reflect.DeepEqual(checkRun, want) { + t.Errorf("Checks.GetCheckRun return %+v, want %+v", checkRun, want) + } +} + +func TestChecksService_GetCheckSuite(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-suites/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{ + "id": 1, + "head_branch":"master", + "head_sha": "deadbeef", + "conclusion": "neutral", + "before": "deadbeefb", + "after": "deadbeefa", + "status": "completed"}`) + }) + checkSuite, _, err := client.Checks.GetCheckSuite(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("Checks.GetCheckSuite return error: %v", err) + } + want := &CheckSuite{ + ID: Int64(1), + HeadBranch: String("master"), + HeadSHA: String("deadbeef"), + AfterSHA: String("deadbeefa"), + BeforeSHA: String("deadbeefb"), + Status: String("completed"), + Conclusion: String("neutral"), + } + if !reflect.DeepEqual(checkSuite, want) { + t.Errorf("Checks.GetCheckSuite return %+v, want %+v", checkSuite, want) + } +} + +func TestChecksService_CreateCheckRun(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-runs", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{ + "id": 1, + "name":"testCreateCheckRun", + "head_sha":"deadbeef", + "status": "in_progress", + "conclusion": null, + "started_at": "2018-05-04T01:14:52Z", + "completed_at": null, + "output":{"title": "Mighty test report", "summary":"", "text":""}}`) + }) + startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + checkRunOpt := CreateCheckRunOptions{ + HeadBranch: "master", + Name: "testCreateCheckRun", + HeadSHA: "deadbeef", + Status: String("in_progress"), + StartedAt: &Timestamp{startedAt}, + Output: &CheckRunOutput{ + Title: String("Mighty test report"), + Summary: String(""), + Text: String(""), + }, + } + + checkRun, _, err := client.Checks.CreateCheckRun(context.Background(), "o", "r", checkRunOpt) + if err != nil { + t.Errorf("Checks.CreateCheckRun return error: %v", err) + } + + want := &CheckRun{ + ID: Int64(1), + Status: String("in_progress"), + StartedAt: &Timestamp{startedAt}, + HeadSHA: String("deadbeef"), + Name: String("testCreateCheckRun"), + Output: &CheckRunOutput{ + Title: String("Mighty test report"), + Summary: String(""), + Text: String(""), + }, + } + if !reflect.DeepEqual(checkRun, want) { + t.Errorf("Checks.CreateCheckRun return %+v, want %+v", checkRun, want) + } +} + +func TestChecksService_ListCheckRunAnnotations(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-runs/1/annotations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + testFormValues(t, r, values{ + "page": "1", + }) + fmt.Fprint(w, `[{ + "path": "README.md", + "blob_href": "https://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md", + "start_line": 2, + "end_line": 2, + "annotation_level": "warning", + "message": "Check your spelling for 'banaas'.", + "title": "Spell check", + "raw_details": "Do you mean 'bananas' or 'banana'?"}]`, + ) + }) + + checkRunAnnotations, _, err := client.Checks.ListCheckRunAnnotations(context.Background(), "o", "r", 1, &ListOptions{Page: 1}) + if err != nil { + t.Errorf("Checks.ListCheckRunAnnotations return error: %v", err) + } + + want := []*CheckRunAnnotation{{ + Path: String("README.md"), + BlobHRef: String("https://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md"), + StartLine: Int(2), + EndLine: Int(2), + AnnotationLevel: String("warning"), + Message: String("Check your spelling for 'banaas'."), + RawDetails: String("Do you mean 'bananas' or 'banana'?"), + Title: String("Spell check"), + }} + + if !reflect.DeepEqual(checkRunAnnotations, want) { + t.Errorf("Checks.ListCheckRunAnnotations returned %+v, want %+v", checkRunAnnotations, want) + } +} + +func TestChecksService_UpdateCheckRun(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{ + "id": 1, + "name":"testUpdateCheckRun", + "head_sha":"deadbeef", + "status": "completed", + "conclusion": "neutral", + "started_at": "2018-05-04T01:14:52Z", + "completed_at": "2018-05-04T01:14:52Z", + "output":{"title": "Mighty test report", "summary":"There are 0 failures, 2 warnings and 1 notice", "text":"You may have misspelled some words."}}`) + }) + startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + updateCheckRunOpt := UpdateCheckRunOptions{ + HeadBranch: String("master"), + Name: "testUpdateCheckRun", + HeadSHA: String("deadbeef"), + Status: String("completed"), + CompletedAt: &Timestamp{startedAt}, + Output: &CheckRunOutput{ + Title: String("Mighty test report"), + Summary: String("There are 0 failures, 2 warnings and 1 notice"), + Text: String("You may have misspelled some words."), + }, + } + + checkRun, _, err := client.Checks.UpdateCheckRun(context.Background(), "o", "r", 1, updateCheckRunOpt) + if err != nil { + t.Errorf("Checks.UpdateCheckRun return error: %v", err) + } + + want := &CheckRun{ + ID: Int64(1), + Status: String("completed"), + StartedAt: &Timestamp{startedAt}, + CompletedAt: &Timestamp{startedAt}, + Conclusion: String("neutral"), + HeadSHA: String("deadbeef"), + Name: String("testUpdateCheckRun"), + Output: &CheckRunOutput{ + Title: String("Mighty test report"), + Summary: String("There are 0 failures, 2 warnings and 1 notice"), + Text: String("You may have misspelled some words."), + }, + } + if !reflect.DeepEqual(checkRun, want) { + t.Errorf("Checks.UpdateCheckRun return %+v, want %+v", checkRun, want) + } +} + +func TestChecksService_ListCheckRunsForRef(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/commits/master/check-runs", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + testFormValues(t, r, values{ + "check_name": "testing", + "page": "1", + "status": "completed", + "filter": "all", + }) + fmt.Fprint(w, `{"total_count":1, + "check_runs": [{ + "id": 1, + "head_sha": "deadbeef", + "status": "completed", + "conclusion": "neutral", + "started_at": "2018-05-04T01:14:52Z", + "completed_at": "2018-05-04T01:14:52Z"}]}`, + ) + }) + + opt := &ListCheckRunsOptions{ + CheckName: String("testing"), + Status: String("completed"), + Filter: String("all"), + ListOptions: ListOptions{Page: 1}, + } + checkRuns, _, err := client.Checks.ListCheckRunsForRef(context.Background(), "o", "r", "master", opt) + if err != nil { + t.Errorf("Checks.ListCheckRunsForRef return error: %v", err) + } + startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + want := &ListCheckRunsResults{ + Total: Int(1), + CheckRuns: []*CheckRun{{ + ID: Int64(1), + Status: String("completed"), + StartedAt: &Timestamp{startedAt}, + CompletedAt: &Timestamp{startedAt}, + Conclusion: String("neutral"), + HeadSHA: String("deadbeef"), + }}, + } + + if !reflect.DeepEqual(checkRuns, want) { + t.Errorf("Checks.ListCheckRunsForRef returned %+v, want %+v", checkRuns, want) + } +} + +func TestChecksService_ListCheckRunsCheckSuite(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-suites/1/check-runs", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + testFormValues(t, r, values{ + "check_name": "testing", + "page": "1", + "status": "completed", + "filter": "all", + }) + fmt.Fprint(w, `{"total_count":1, + "check_runs": [{ + "id": 1, + "head_sha": "deadbeef", + "status": "completed", + "conclusion": "neutral", + "started_at": "2018-05-04T01:14:52Z", + "completed_at": "2018-05-04T01:14:52Z"}]}`, + ) + }) + + opt := &ListCheckRunsOptions{ + CheckName: String("testing"), + Status: String("completed"), + Filter: String("all"), + ListOptions: ListOptions{Page: 1}, + } + checkRuns, _, err := client.Checks.ListCheckRunsCheckSuite(context.Background(), "o", "r", 1, opt) + if err != nil { + t.Errorf("Checks.ListCheckRunsCheckSuite return error: %v", err) + } + startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z") + want := &ListCheckRunsResults{ + Total: Int(1), + CheckRuns: []*CheckRun{{ + ID: Int64(1), + Status: String("completed"), + StartedAt: &Timestamp{startedAt}, + CompletedAt: &Timestamp{startedAt}, + Conclusion: String("neutral"), + HeadSHA: String("deadbeef"), + }}, + } + + if !reflect.DeepEqual(checkRuns, want) { + t.Errorf("Checks.ListCheckRunsCheckSuite returned %+v, want %+v", checkRuns, want) + } +} + +func TestChecksService_ListCheckSuiteForRef(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/commits/master/check-suites", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + testFormValues(t, r, values{ + "check_name": "testing", + "page": "1", + "app_id": "2", + }) + fmt.Fprint(w, `{"total_count":1, + "check_suites": [{ + "id": 1, + "head_sha": "deadbeef", + "head_branch": "master", + "status": "completed", + "conclusion": "neutral", + "before": "deadbeefb", + "after": "deadbeefa"}]}`, + ) + }) + + opt := &ListCheckSuiteOptions{ + CheckName: String("testing"), + AppID: Int(2), + ListOptions: ListOptions{Page: 1}, + } + checkSuites, _, err := client.Checks.ListCheckSuitesForRef(context.Background(), "o", "r", "master", opt) + if err != nil { + t.Errorf("Checks.ListCheckSuitesForRef return error: %v", err) + } + want := &ListCheckSuiteResults{ + Total: Int(1), + CheckSuites: []*CheckSuite{{ + ID: Int64(1), + Status: String("completed"), + Conclusion: String("neutral"), + HeadSHA: String("deadbeef"), + HeadBranch: String("master"), + BeforeSHA: String("deadbeefb"), + AfterSHA: String("deadbeefa"), + }}, + } + + if !reflect.DeepEqual(checkSuites, want) { + t.Errorf("Checks.ListCheckSuitesForRef returned %+v, want %+v", checkSuites, want) + } +} + +func TestChecksService_SetCheckSuitePreferences(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-suites/preferences", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{"preferences":{"auto_trigger_checks":[{"app_id": 2,"setting": false}]}}`) + }) + p := &PreferenceList{ + AutoTriggerChecks: []*AutoTriggerCheck{{ + AppID: Int64(2), + Setting: Bool(false), + }}, + } + opt := CheckSuitePreferenceOptions{PreferenceList: p} + prefResults, _, err := client.Checks.SetCheckSuitePreferences(context.Background(), "o", "r", opt) + if err != nil { + t.Errorf("Checks.SetCheckSuitePreferences return error: %v", err) + } + + want := &CheckSuitePreferenceResults{ + Preferences: p, + } + + if !reflect.DeepEqual(prefResults, want) { + t.Errorf("Checks.SetCheckSuitePreferences return %+v, want %+v", prefResults, want) + } +} + +func TestChecksService_CreateCheckSuite(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-suites", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + fmt.Fprint(w, `{ + "id": 2, + "head_branch":"master", + "head_sha":"deadbeef", + "status": "completed", + "conclusion": "neutral", + "before": "deadbeefb", + "after": "deadbeefa"}`) + }) + + checkSuiteOpt := CreateCheckSuiteOptions{ + HeadSHA: "deadbeef", + HeadBranch: String("master"), + } + + checkSuite, _, err := client.Checks.CreateCheckSuite(context.Background(), "o", "r", checkSuiteOpt) + if err != nil { + t.Errorf("Checks.CreateCheckSuite return error: %v", err) + } + + want := &CheckSuite{ + ID: Int64(2), + Status: String("completed"), + HeadSHA: String("deadbeef"), + HeadBranch: String("master"), + Conclusion: String("neutral"), + BeforeSHA: String("deadbeefb"), + AfterSHA: String("deadbeefa"), + } + if !reflect.DeepEqual(checkSuite, want) { + t.Errorf("Checks.CreateCheckSuite return %+v, want %+v", checkSuite, want) + } +} + +func TestChecksService_ReRequestCheckSuite(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-suites/1/rerequest", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + w.WriteHeader(http.StatusCreated) + }) + resp, err := client.Checks.ReRequestCheckSuite(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("Checks.ReRequestCheckSuite return error: %v", err) + } + if got, want := resp.StatusCode, http.StatusCreated; got != want { + t.Errorf("Checks.ReRequestCheckSuite = %v, want %v", got, want) + } +} diff --git a/vendor/github.com/google/go-github/github/doc.go b/vendor/github.com/google/go-github/github/doc.go index 4ba03cb3c..96445d264 100644 --- a/vendor/github.com/google/go-github/github/doc.go +++ b/vendor/github.com/google/go-github/github/doc.go @@ -30,6 +30,13 @@ The services of a client divide the API into logical chunks and correspond to the structure of the GitHub API documentation at https://developer.github.com/v3/. +NOTE: Using the https://godoc.org/context package, one can easily +pass cancelation signals and deadlines to various services of the client for +handling a request. In case there is no context available, then context.Background() +can be used as a starting point. + +For more sample code snippets, head over to the https://github.com/google/go-github/tree/master/example directory. + Authentication The go-github library does not directly handle authentication. Instead, when @@ -176,16 +183,5 @@ github.Response struct. opt.Page = resp.NextPage } -Google App Engine - -Go on App Engine Classic (which as of this writing uses Go 1.6) can not use -the "context" import and still relies on "golang.org/x/net/context". -As a result, if you wish to continue to use "go-github" on App Engine Classic, -you will need to rewrite all the "context" imports using the following command: - - gofmt -w -r '"context" -> "golang.org/x/net/context"' *.go - -See "with_appengine.go" for more details. - */ package github diff --git a/vendor/github.com/google/go-github/github/event.go b/vendor/github.com/google/go-github/github/event.go new file mode 100644 index 000000000..04c8845a1 --- /dev/null +++ b/vendor/github.com/google/go-github/github/event.go @@ -0,0 +1,126 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "encoding/json" + "time" +) + +// Event represents a GitHub event. +type Event struct { + Type *string `json:"type,omitempty"` + Public *bool `json:"public,omitempty"` + RawPayload *json.RawMessage `json:"payload,omitempty"` + Repo *Repository `json:"repo,omitempty"` + Actor *User `json:"actor,omitempty"` + Org *Organization `json:"org,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + ID *string `json:"id,omitempty"` +} + +func (e Event) String() string { + return Stringify(e) +} + +// ParsePayload parses the event payload. For recognized event types, +// a value of the corresponding struct type will be returned. +func (e *Event) ParsePayload() (payload interface{}, err error) { + switch *e.Type { + case "CheckRunEvent": + payload = &CheckRunEvent{} + case "CheckSuiteEvent": + payload = &CheckSuiteEvent{} + case "CommitCommentEvent": + payload = &CommitCommentEvent{} + case "CreateEvent": + payload = &CreateEvent{} + case "DeleteEvent": + payload = &DeleteEvent{} + case "DeploymentEvent": + payload = &DeploymentEvent{} + case "DeploymentStatusEvent": + payload = &DeploymentStatusEvent{} + case "ForkEvent": + payload = &ForkEvent{} + case "GitHubAppAuthorizationEvent": + payload = &GitHubAppAuthorizationEvent{} + case "GollumEvent": + payload = &GollumEvent{} + case "InstallationEvent": + payload = &InstallationEvent{} + case "InstallationRepositoriesEvent": + payload = &InstallationRepositoriesEvent{} + case "IssueCommentEvent": + payload = &IssueCommentEvent{} + case "IssuesEvent": + payload = &IssuesEvent{} + case "LabelEvent": + payload = &LabelEvent{} + case "MarketplacePurchaseEvent": + payload = &MarketplacePurchaseEvent{} + case "MemberEvent": + payload = &MemberEvent{} + case "MembershipEvent": + payload = &MembershipEvent{} + case "MilestoneEvent": + payload = &MilestoneEvent{} + case "OrganizationEvent": + payload = &OrganizationEvent{} + case "OrgBlockEvent": + payload = &OrgBlockEvent{} + case "PageBuildEvent": + payload = &PageBuildEvent{} + case "PingEvent": + payload = &PingEvent{} + case "ProjectEvent": + payload = &ProjectEvent{} + case "ProjectCardEvent": + payload = &ProjectCardEvent{} + case "ProjectColumnEvent": + payload = &ProjectColumnEvent{} + case "PublicEvent": + payload = &PublicEvent{} + case "PullRequestEvent": + payload = &PullRequestEvent{} + case "PullRequestReviewEvent": + payload = &PullRequestReviewEvent{} + case "PullRequestReviewCommentEvent": + payload = &PullRequestReviewCommentEvent{} + case "PushEvent": + payload = &PushEvent{} + case "ReleaseEvent": + payload = &ReleaseEvent{} + case "RepositoryEvent": + payload = &RepositoryEvent{} + case "RepositoryVulnerabilityAlertEvent": + payload = &RepositoryVulnerabilityAlertEvent{} + case "StatusEvent": + payload = &StatusEvent{} + case "TeamEvent": + payload = &TeamEvent{} + case "TeamAddEvent": + payload = &TeamAddEvent{} + case "WatchEvent": + payload = &WatchEvent{} + } + err = json.Unmarshal(*e.RawPayload, &payload) + return payload, err +} + +// Payload returns the parsed event payload. For recognized event types, +// a value of the corresponding struct type will be returned. +// +// Deprecated: Use ParsePayload instead, which returns an error +// rather than panics if JSON unmarshaling raw payload fails. +func (e *Event) Payload() (payload interface{}) { + var err error + payload, err = e.ParsePayload() + if err != nil { + panic(err) + } + return payload +} diff --git a/vendor/github.com/google/go-github/github/event_types.go b/vendor/github.com/google/go-github/github/event_types.go index c6b29b9a2..0d70a474c 100644 --- a/vendor/github.com/google/go-github/github/event_types.go +++ b/vendor/github.com/google/go-github/github/event_types.go @@ -7,6 +7,47 @@ package github +// RequestedAction is included in a CheckRunEvent when a user has invoked an action, +// i.e. when the CheckRunEvent's Action field is "requested_action". +type RequestedAction struct { + Identifier string `json:"identifier"` // The integrator reference of the action requested by the user. +} + +// CheckRunEvent is triggered when a check run is "created", "updated", or "re-requested". +// The Webhook event name is "check_run". +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#checkrunevent +type CheckRunEvent struct { + CheckRun *CheckRun `json:"check_run,omitempty"` + // The action performed. Can be "created", "updated", "rerequested" or "requested_action". + Action *string `json:"action,omitempty"` + + // The following fields are only populated by Webhook events. + Repo *Repository `json:"repository,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` + + // The action requested by the user. Populated when the Action is "requested_action". + RequestedAction *RequestedAction `json:"requested_action,omitempty"` // +} + +// CheckSuiteEvent is triggered when a check suite is "completed", "requested", or "re-requested". +// The Webhook event name is "check_suite". +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#checksuiteevent +type CheckSuiteEvent struct { + CheckSuite *CheckSuite `json:"check_suite,omitempty"` + // The action performed. Can be "completed", "requested" or "re-requested". + Action *string `json:"action,omitempty"` + + // The following fields are only populated by Webhook events. + Repo *Repository `json:"repository,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` +} + // CommitCommentEvent is triggered when a commit comment is created. // The Webhook event name is "commit_comment". // @@ -107,6 +148,18 @@ type ForkEvent struct { Installation *Installation `json:"installation,omitempty"` } +// GitHubAppAuthorizationEvent is triggered when a user's authorization for a +// GitHub Application is revoked. +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#githubappauthorizationevent +type GitHubAppAuthorizationEvent struct { + // The action performed. Can be "revoked". + Action *string `json:"action,omitempty"` + + // The following fields are only populated by Webhook events. + Sender *User `json:"sender,omitempty"` +} + // Page represents a single Wiki page. type Page struct { PageName *string `json:"page_name,omitempty"` @@ -194,6 +247,7 @@ type TeamChange struct { type InstallationEvent struct { // The action that was performed. Can be either "created" or "deleted". Action *string `json:"action,omitempty"` + Repositories []*Repository `json:"repositories,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } @@ -268,6 +322,24 @@ type LabelEvent struct { Installation *Installation `json:"installation,omitempty"` } +// MarketplacePurchaseEvent is triggered when a user purchases, cancels, or changes +// their GitHub Marketplace plan. +// Webhook event name "marketplace_purchase". +// +// Github API docs: https://developer.github.com/v3/activity/events/types/#marketplacepurchaseevent +type MarketplacePurchaseEvent struct { + // Action is the action that was performed. Possible values are: + // "purchased", "cancelled", "pending_change", "pending_change_cancelled", "changed". + Action *string `json:"action,omitempty"` + + // The following fields are only populated by Webhook events. + EffectiveDate *Timestamp `json:"effective_date,omitempty"` + MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"` + PreviousMarketplacePurchase *MarketplacePurchase `json:"previous_marketplace_purchase,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` +} + // MemberEvent is triggered when a user is added as a collaborator to a repository. // The Webhook event name is "member". // @@ -374,7 +446,7 @@ type PageBuildEvent struct { Build *PagesBuild `json:"build,omitempty"` // The following fields are only populated by Webhook events. - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Repo *Repository `json:"repository,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` @@ -387,7 +459,7 @@ type PingEvent struct { // Random string of GitHub zen. Zen *string `json:"zen,omitempty"` // The ID of the webhook that triggered the ping. - HookID *int `json:"hook_id,omitempty"` + HookID *int64 `json:"hook_id,omitempty"` // The webhook configuration. Hook *Hook `json:"hook,omitempty"` Installation *Installation `json:"installation,omitempty"` @@ -416,7 +488,7 @@ type ProjectEvent struct { type ProjectCardEvent struct { Action *string `json:"action,omitempty"` Changes *ProjectCardChange `json:"changes,omitempty"` - AfterID *int `json:"after_id,omitempty"` + AfterID *int64 `json:"after_id,omitempty"` ProjectCard *ProjectCard `json:"project_card,omitempty"` // The following fields are only populated by Webhook events. @@ -433,7 +505,7 @@ type ProjectCardEvent struct { type ProjectColumnEvent struct { Action *string `json:"action,omitempty"` Changes *ProjectColumnChange `json:"changes,omitempty"` - AfterID *int `json:"after_id,omitempty"` + AfterID *int64 `json:"after_id,omitempty"` ProjectColumn *ProjectColumn `json:"project_column,omitempty"` // The following fields are only populated by Webhook events. @@ -461,20 +533,31 @@ type PublicEvent struct { // // GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestevent type PullRequestEvent struct { - // Action is the action that was performed. Possible values are: "assigned", - // "unassigned", "labeled", "unlabeled", "opened", "closed", or "reopened", - // "synchronize", "edited". If the action is "closed" and the merged key is false, + // Action is the action that was performed. Possible values are: + // "assigned", "unassigned", "review_requested", "review_request_removed", "labeled", "unlabeled", + // "opened", "closed", "reopened", "synchronize", "edited". + // If the action is "closed" and the merged key is false, // the pull request was closed with unmerged commits. If the action is "closed" // and the merged key is true, the pull request was merged. Action *string `json:"action,omitempty"` + Assignee *User `json:"assignee,omitempty"` Number *int `json:"number,omitempty"` PullRequest *PullRequest `json:"pull_request,omitempty"` // The following fields are only populated by Webhook events. - Changes *EditChange `json:"changes,omitempty"` - Repo *Repository `json:"repository,omitempty"` - Sender *User `json:"sender,omitempty"` - Installation *Installation `json:"installation,omitempty"` + Changes *EditChange `json:"changes,omitempty"` + // RequestedReviewer is populated in "review_requested", "review_request_removed" event deliveries. + // A request affecting multiple reviewers at once is split into multiple + // such event deliveries, each with a single, different RequestedReviewer. + RequestedReviewer *User `json:"requested_reviewer,omitempty"` + Repo *Repository `json:"repository,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` + Label *Label `json:"label,omitempty"` // Populated in "labeled" event deliveries. + + // The following field is only present when the webhook is triggered on + // a repository belonging to an organization. + Organization *Organization `json:"organization,omitempty"` } // PullRequestReviewEvent is triggered when a review is submitted on a pull @@ -521,7 +604,7 @@ type PullRequestReviewCommentEvent struct { // // GitHub API docs: https://developer.github.com/v3/activity/events/types/#pushevent type PushEvent struct { - PushID *int `json:"push_id,omitempty"` + PushID *int64 `json:"push_id,omitempty"` Head *string `json:"head,omitempty"` Ref *string `json:"ref,omitempty"` Size *int `json:"size,omitempty"` @@ -573,38 +656,39 @@ func (p PushEventCommit) String() string { // PushEventRepository represents the repo object in a PushEvent payload. type PushEventRepository struct { - ID *int `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - FullName *string `json:"full_name,omitempty"` - Owner *PushEventRepoOwner `json:"owner,omitempty"` - Private *bool `json:"private,omitempty"` - Description *string `json:"description,omitempty"` - Fork *bool `json:"fork,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - PushedAt *Timestamp `json:"pushed_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - Homepage *string `json:"homepage,omitempty"` - Size *int `json:"size,omitempty"` - StargazersCount *int `json:"stargazers_count,omitempty"` - WatchersCount *int `json:"watchers_count,omitempty"` - Language *string `json:"language,omitempty"` - HasIssues *bool `json:"has_issues,omitempty"` - HasDownloads *bool `json:"has_downloads,omitempty"` - HasWiki *bool `json:"has_wiki,omitempty"` - HasPages *bool `json:"has_pages,omitempty"` - ForksCount *int `json:"forks_count,omitempty"` - OpenIssuesCount *int `json:"open_issues_count,omitempty"` - DefaultBranch *string `json:"default_branch,omitempty"` - MasterBranch *string `json:"master_branch,omitempty"` - Organization *string `json:"organization,omitempty"` - URL *string `json:"url,omitempty"` - ArchiveURL *string `json:"archive_url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - StatusesURL *string `json:"statuses_url,omitempty"` - GitURL *string `json:"git_url,omitempty"` - SSHURL *string `json:"ssh_url,omitempty"` - CloneURL *string `json:"clone_url,omitempty"` - SVNURL *string `json:"svn_url,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Name *string `json:"name,omitempty"` + FullName *string `json:"full_name,omitempty"` + Owner *User `json:"owner,omitempty"` + Private *bool `json:"private,omitempty"` + Description *string `json:"description,omitempty"` + Fork *bool `json:"fork,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + PushedAt *Timestamp `json:"pushed_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + Homepage *string `json:"homepage,omitempty"` + Size *int `json:"size,omitempty"` + StargazersCount *int `json:"stargazers_count,omitempty"` + WatchersCount *int `json:"watchers_count,omitempty"` + Language *string `json:"language,omitempty"` + HasIssues *bool `json:"has_issues,omitempty"` + HasDownloads *bool `json:"has_downloads,omitempty"` + HasWiki *bool `json:"has_wiki,omitempty"` + HasPages *bool `json:"has_pages,omitempty"` + ForksCount *int `json:"forks_count,omitempty"` + OpenIssuesCount *int `json:"open_issues_count,omitempty"` + DefaultBranch *string `json:"default_branch,omitempty"` + MasterBranch *string `json:"master_branch,omitempty"` + Organization *string `json:"organization,omitempty"` + URL *string `json:"url,omitempty"` + ArchiveURL *string `json:"archive_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + StatusesURL *string `json:"statuses_url,omitempty"` + GitURL *string `json:"git_url,omitempty"` + SSHURL *string `json:"ssh_url,omitempty"` + CloneURL *string `json:"clone_url,omitempty"` + SVNURL *string `json:"svn_url,omitempty"` } // PushEventRepoOwner is a basic representation of user/org in a PushEvent payload. @@ -647,6 +731,27 @@ type RepositoryEvent struct { Installation *Installation `json:"installation,omitempty"` } +// RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved. +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent +type RepositoryVulnerabilityAlertEvent struct { + // Action is the action that was performed. This can be: "create", "dismiss", "resolve". + Action *string `json:"action,omitempty"` + + //The security alert of the vulnerable dependency. + Alert *struct { + ID *int64 `json:"id,omitempty"` + AffectedRange *string `json:"affected_range,omitempty"` + AffectedPackageName *string `json:"affected_package_name,omitempty"` + ExternalReference *string `json:"external_reference,omitempty"` + ExternalIdentifier *string `json:"external_identifier,omitempty"` + FixedIn *string `json:"fixed_in,omitempty"` + Dismisser *User `json:"dismisser,omitempty"` + DismissReason *string `json:"dismiss_reason,omitempty"` + DismissedAt *Timestamp `json:"dismissed_at,omitempty"` + } `json:"alert,omitempty"` +} + // StatusEvent is triggered when the status of a Git commit changes. // The Webhook event name is "status". // @@ -663,7 +768,7 @@ type StatusEvent struct { Branches []*Branch `json:"branches,omitempty"` // The following fields are only populated by Webhook events. - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Name *string `json:"name,omitempty"` Context *string `json:"context,omitempty"` Commit *RepositoryCommit `json:"commit,omitempty"` diff --git a/vendor/github.com/google/go-github/github/examples_test.go b/vendor/github.com/google/go-github/github/examples_test.go index f09d6505a..67437a7db 100644 --- a/vendor/github.com/google/go-github/github/examples_test.go +++ b/vendor/github.com/google/go-github/github/examples_test.go @@ -3,6 +3,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// These examples are inlined in godoc. + package github_test import ( @@ -10,7 +12,7 @@ import ( "fmt" "log" - "github.com/google/go-github/github" + "github.com/google/go-github/v19/github" ) func ExampleClient_Markdown() { @@ -59,6 +61,35 @@ func ExampleRepositoriesService_List() { fmt.Printf("Recently updated repositories by %q: %v", user, github.Stringify(repos)) } +func ExampleRepositoriesService_CreateFile() { + // In this example we're creating a new file in a repository using the + // Contents API. Only 1 file per commit can be managed through that API. + + // Note that authentication is needed here as you are performing a modification + // so you will need to modify the example to provide an oauth client to + // github.NewClient() instead of nil. See the following documentation for more + // information on how to authenticate with the client: + // https://godoc.org/github.com/google/go-github/github#hdr-Authentication + client := github.NewClient(nil) + + ctx := context.Background() + fileContent := []byte("This is the content of my file\nand the 2nd line of it") + + // Note: the file needs to be absent from the repository as you are not + // specifying a SHA reference here. + opts := &github.RepositoryContentFileOptions{ + Message: github.String("This is my commit message"), + Content: fileContent, + Branch: github.String("master"), + Committer: &github.CommitAuthor{Name: github.String("FirstName LastName"), Email: github.String("user@example.com")}, + } + _, _, err := client.Repositories.CreateFile(ctx, "myOrganization", "myRepository", "myNewFile.md", opts) + if err != nil { + fmt.Println(err) + return + } +} + func ExampleUsersService_ListAll() { client := github.NewClient(nil) opts := &github.UserListOptions{} @@ -74,3 +105,66 @@ func ExampleUsersService_ListAll() { // Process users... } } + +func ExamplePullRequestsService_Create() { + // In this example we're creating a PR and displaying the HTML url at the end. + + // Note that authentication is needed here as you are performing a modification + // so you will need to modify the example to provide an oauth client to + // github.NewClient() instead of nil. See the following documentation for more + // information on how to authenticate with the client: + // https://godoc.org/github.com/google/go-github/github#hdr-Authentication + client := github.NewClient(nil) + + newPR := &github.NewPullRequest{ + Title: github.String("My awesome pull request"), + Head: github.String("branch_to_merge"), + Base: github.String("master"), + Body: github.String("This is the description of the PR created with the package `github.com/google/go-github/github`"), + MaintainerCanModify: github.Bool(true), + } + + pr, _, err := client.PullRequests.Create(context.Background(), "myOrganization", "myRepository", newPR) + if err != nil { + fmt.Println(err) + return + } + + fmt.Printf("PR created: %s\n", pr.GetHTMLURL()) +} + +func ExampleTeamsService_ListTeams() { + // This example shows how to get a team ID corresponding to a given team name. + + // Note that authentication is needed here as you are performing a lookup on + // an organization's administrative configuration, so you will need to modify + // the example to provide an oauth client to github.NewClient() instead of nil. + // See the following documentation for more information on how to authenticate + // with the client: + // https://godoc.org/github.com/google/go-github/github#hdr-Authentication + client := github.NewClient(nil) + + teamName := "Developers team" + ctx := context.Background() + opts := &github.ListOptions{} + + for { + teams, resp, err := client.Teams.ListTeams(ctx, "myOrganization", opts) + if err != nil { + fmt.Println(err) + return + } + for _, t := range teams { + if t.GetName() == teamName { + fmt.Printf("Team %q has ID %d\n", teamName, t.GetID()) + return + } + } + if resp.NextPage == 0 { + break + } + opts.Page = resp.NextPage + } + + fmt.Printf("Team %q was not found\n", teamName) +} diff --git a/vendor/github.com/google/go-github/github/gen-accessors.go b/vendor/github.com/google/go-github/github/gen-accessors.go index 131c56cbf..fe92206fc 100644 --- a/vendor/github.com/google/go-github/github/gen-accessors.go +++ b/vendor/github.com/google/go-github/github/gen-accessors.go @@ -25,7 +25,6 @@ import ( "sort" "strings" "text/template" - "time" ) const ( @@ -37,8 +36,8 @@ var ( sourceTmpl = template.Must(template.New("source").Parse(source)) - // blacklist lists which "struct.method" combos to not generate. - blacklist = map[string]bool{ + // blacklistStructMethod lists "struct.method" combos to skip. + blacklistStructMethod = map[string]bool{ "RepositoryContent.GetContent": true, "Client.GetBaseURL": true, "Client.GetUploadURL": true, @@ -46,6 +45,10 @@ var ( "RateLimitError.GetResponse": true, "AbuseRateLimitError.GetResponse": true, } + // blacklistStruct lists structs to skip. + blacklistStruct = map[string]bool{ + "Client": true, + } ) func logf(fmt string, args ...interface{}) { @@ -67,7 +70,7 @@ func main() { for pkgName, pkg := range pkgs { t := &templateData{ filename: pkgName + fileSuffix, - Year: time.Now().Year(), + Year: 2017, Package: pkgName, Imports: map[string]string{}, } @@ -95,6 +98,16 @@ func (t *templateData) processAST(f *ast.File) error { if !ok { continue } + // Skip unexported identifiers. + if !ts.Name.IsExported() { + logf("Struct %v is unexported; skipping.", ts.Name) + continue + } + // Check if the struct is blacklisted. + if blacklistStruct[ts.Name.Name] { + logf("Struct %v is blacklisted; skipping.", ts.Name) + continue + } st, ok := ts.Type.(*ast.StructType) if !ok { continue @@ -106,8 +119,14 @@ func (t *templateData) processAST(f *ast.File) error { } fieldName := field.Names[0] - if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklist[key] { - logf("Method %v blacklisted; skipping.", key) + // Skip unexported identifiers. + if !fieldName.IsExported() { + logf("Field %v is unexported; skipping.", fieldName) + continue + } + // Check if "struct.method" is blacklisted. + if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklistStructMethod[key] { + logf("Method %v is blacklisted; skipping.", key) continue } @@ -139,7 +158,7 @@ func (t *templateData) dump() error { return nil } - // Sort getters by ReceiverType.FieldName + // Sort getters by ReceiverType.FieldName. sort.Sort(byName(t.Getters)) var buf bytes.Buffer @@ -155,7 +174,7 @@ func (t *templateData) dump() error { return ioutil.WriteFile(t.filename, clean, 0644) } -func newGetter(receiverType, fieldName, fieldType, zeroValue string) *getter { +func newGetter(receiverType, fieldName, fieldType, zeroValue string, namedStruct bool) *getter { return &getter{ sortVal: strings.ToLower(receiverType) + "." + strings.ToLower(fieldName), ReceiverVar: strings.ToLower(receiverType[:1]), @@ -163,6 +182,7 @@ func newGetter(receiverType, fieldName, fieldType, zeroValue string) *getter { FieldName: fieldName, FieldType: fieldType, ZeroValue: zeroValue, + NamedStruct: namedStruct, } } @@ -176,13 +196,14 @@ func (t *templateData) addArrayType(x *ast.ArrayType, receiverType, fieldName st return } - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, "[]"+eltType, "nil")) + t.Getters = append(t.Getters, newGetter(receiverType, fieldName, "[]"+eltType, "nil", false)) } func (t *templateData) addIdent(x *ast.Ident, receiverType, fieldName string) { var zeroValue string + var namedStruct = false switch x.String() { - case "int": + case "int", "int64": zeroValue = "0" case "string": zeroValue = `""` @@ -190,11 +211,12 @@ func (t *templateData) addIdent(x *ast.Ident, receiverType, fieldName string) { zeroValue = "false" case "Timestamp": zeroValue = "Timestamp{}" - default: // other structs handled by their receivers directly. - return + default: + zeroValue = "nil" + namedStruct = true } - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, x.String(), zeroValue)) + t.Getters = append(t.Getters, newGetter(receiverType, fieldName, x.String(), zeroValue, namedStruct)) } func (t *templateData) addMapType(x *ast.MapType, receiverType, fieldName string) { @@ -218,11 +240,11 @@ func (t *templateData) addMapType(x *ast.MapType, receiverType, fieldName string fieldType := fmt.Sprintf("map[%v]%v", keyType, valueType) zeroValue := fmt.Sprintf("map[%v]%v{}", keyType, valueType) - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue)) + t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue, false)) } func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) { - if strings.ToLower(fieldName[:1]) == fieldName[:1] { // non-exported field + if strings.ToLower(fieldName[:1]) == fieldName[:1] { // Non-exported field. return } @@ -243,7 +265,7 @@ func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldN if xX == "time" && x.Sel.Name == "Duration" { zeroValue = "0" } - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue)) + t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue, false)) default: logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x) } @@ -258,12 +280,13 @@ type templateData struct { } type getter struct { - sortVal string // lower-case version of "ReceiverType.FieldName" - ReceiverVar string // the one-letter variable name to match the ReceiverType + sortVal string // Lower-case version of "ReceiverType.FieldName". + ReceiverVar string // The one-letter variable name to match the ReceiverType. ReceiverType string FieldName string FieldType string ZeroValue string + NamedStruct bool // Getter for named struct. } type byName []*getter @@ -288,6 +311,15 @@ import ( ) {{end}} {{range .Getters}} +{{if .NamedStruct}} +// Get{{.FieldName}} returns the {{.FieldName}} field. +func ({{.ReceiverVar}} *{{.ReceiverType}}) Get{{.FieldName}}() *{{.FieldType}} { + if {{.ReceiverVar}} == nil { + return {{.ZeroValue}} + } + return {{.ReceiverVar}}.{{.FieldName}} +} +{{else}} // Get{{.FieldName}} returns the {{.FieldName}} field if it's non-nil, zero value otherwise. func ({{.ReceiverVar}} *{{.ReceiverType}}) Get{{.FieldName}}() {{.FieldType}} { if {{.ReceiverVar}} == nil || {{.ReceiverVar}}.{{.FieldName}} == nil { @@ -296,4 +328,5 @@ func ({{.ReceiverVar}} *{{.ReceiverType}}) Get{{.FieldName}}() {{.FieldType}} { return *{{.ReceiverVar}}.{{.FieldName}} } {{end}} +{{end}} ` diff --git a/vendor/github.com/google/go-github/github/gists.go b/vendor/github.com/google/go-github/github/gists.go index 15276ea1d..15e0bc2cd 100644 --- a/vendor/github.com/google/go-github/github/gists.go +++ b/vendor/github.com/google/go-github/github/gists.go @@ -30,6 +30,7 @@ type Gist struct { GitPushURL *string `json:"git_push_url,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (g Gist) String() string { @@ -60,6 +61,7 @@ type GistCommit struct { User *User `json:"user,omitempty"` ChangeStatus *CommitStats `json:"change_status,omitempty"` CommittedAt *Timestamp `json:"committed_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (gc GistCommit) String() string { @@ -73,6 +75,7 @@ type GistFork struct { ID *string `json:"id,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (gf GistFork) String() string { @@ -175,6 +178,7 @@ func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, er if err != nil { return nil, nil, err } + gist := new(Gist) resp, err := s.client.Do(ctx, req, gist) if err != nil { @@ -193,6 +197,7 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, if err != nil { return nil, nil, err } + gist := new(Gist) resp, err := s.client.Do(ctx, req, gist) if err != nil { @@ -211,6 +216,7 @@ func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response if err != nil { return nil, nil, err } + g := new(Gist) resp, err := s.client.Do(ctx, req, g) if err != nil { @@ -229,6 +235,7 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, if err != nil { return nil, nil, err } + g := new(Gist) resp, err := s.client.Do(ctx, req, g) if err != nil { diff --git a/vendor/github.com/google/go-github/github/gists_comments.go b/vendor/github.com/google/go-github/github/gists_comments.go index 2d0722375..d5322e3d8 100644 --- a/vendor/github.com/google/go-github/github/gists_comments.go +++ b/vendor/github.com/google/go-github/github/gists_comments.go @@ -13,7 +13,7 @@ import ( // GistComment represents a Gist comment. type GistComment struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` Body *string `json:"body,omitempty"` User *User `json:"user,omitempty"` @@ -51,7 +51,7 @@ func (s *GistsService) ListComments(ctx context.Context, gistID string, opt *Lis // GetComment retrieves a single comment from a gist. // // GitHub API docs: https://developer.github.com/v3/gists/comments/#get-a-single-comment -func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int) (*GistComment, *Response, error) { +func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int64) (*GistComment, *Response, error) { u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -89,7 +89,7 @@ func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment // EditComment edits an existing gist comment. // // GitHub API docs: https://developer.github.com/v3/gists/comments/#edit-a-comment -func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int, comment *GistComment) (*GistComment, *Response, error) { +func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, comment *GistComment) (*GistComment, *Response, error) { u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) req, err := s.client.NewRequest("PATCH", u, comment) if err != nil { @@ -108,7 +108,7 @@ func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID // DeleteComment deletes a gist comment. // // GitHub API docs: https://developer.github.com/v3/gists/comments/#delete-a-comment -func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int) (*Response, error) { +func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int64) (*Response, error) { u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/gists_comments_test.go b/vendor/github.com/google/go-github/github/gists_comments_test.go index 4b6841363..d2f5a9534 100644 --- a/vendor/github.com/google/go-github/github/gists_comments_test.go +++ b/vendor/github.com/google/go-github/github/gists_comments_test.go @@ -15,7 +15,7 @@ import ( ) func TestGistsService_ListComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -30,19 +30,22 @@ func TestGistsService_ListComments(t *testing.T) { t.Errorf("Gists.Comments returned error: %v", err) } - want := []*GistComment{{ID: Int(1)}} + want := []*GistComment{{ID: Int64(1)}} if !reflect.DeepEqual(comments, want) { t.Errorf("Gists.ListComments returned %+v, want %+v", comments, want) } } func TestGistsService_ListComments_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.ListComments(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { @@ -55,22 +58,25 @@ func TestGistsService_GetComment(t *testing.T) { t.Errorf("Gists.GetComment returned error: %v", err) } - want := &GistComment{ID: Int(1)} + want := &GistComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Gists.GetComment returned %+v, want %+v", comment, want) } } func TestGistsService_GetComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.GetComment(context.Background(), "%", 1) testURLParseError(t, err) } func TestGistsService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &GistComment{ID: Int(1), Body: String("b")} + input := &GistComment{ID: Int64(1), Body: String("b")} mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { v := new(GistComment) @@ -89,22 +95,25 @@ func TestGistsService_CreateComment(t *testing.T) { t.Errorf("Gists.CreateComment returned error: %v", err) } - want := &GistComment{ID: Int(1)} + want := &GistComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Gists.CreateComment returned %+v, want %+v", comment, want) } } func TestGistsService_CreateComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.CreateComment(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &GistComment{ID: Int(1), Body: String("b")} + input := &GistComment{ID: Int64(1), Body: String("b")} mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { v := new(GistComment) @@ -123,19 +132,22 @@ func TestGistsService_EditComment(t *testing.T) { t.Errorf("Gists.EditComment returned error: %v", err) } - want := &GistComment{ID: Int(1)} + want := &GistComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Gists.EditComment returned %+v, want %+v", comment, want) } } func TestGistsService_EditComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.EditComment(context.Background(), "%", 1, nil) testURLParseError(t, err) } func TestGistsService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { @@ -149,6 +161,9 @@ func TestGistsService_DeleteComment(t *testing.T) { } func TestGistsService_DeleteComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.DeleteComment(context.Background(), "%", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/gists_test.go b/vendor/github.com/google/go-github/github/gists_test.go index 6065f277d..3d31c9aca 100644 --- a/vendor/github.com/google/go-github/github/gists_test.go +++ b/vendor/github.com/google/go-github/github/gists_test.go @@ -16,7 +16,7 @@ import ( ) func TestGistsService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -42,7 +42,7 @@ func TestGistsService_List_specifiedUser(t *testing.T) { } func TestGistsService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) { @@ -62,12 +62,15 @@ func TestGistsService_List_authenticatedUser(t *testing.T) { } func TestGistsService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -93,7 +96,7 @@ func TestGistsService_ListAll(t *testing.T) { } func TestGistsService_ListStarred(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -119,7 +122,7 @@ func TestGistsService_ListStarred(t *testing.T) { } func TestGistsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { @@ -139,12 +142,15 @@ func TestGistsService_Get(t *testing.T) { } func TestGistsService_Get_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Get(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_GetRevision(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/s", func(w http.ResponseWriter, r *http.Request) { @@ -164,12 +170,15 @@ func TestGistsService_GetRevision(t *testing.T) { } func TestGistsService_GetRevision_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.GetRevision(context.Background(), "%", "%") testURLParseError(t, err) } func TestGistsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Gist{ @@ -222,7 +231,7 @@ func TestGistsService_Create(t *testing.T) { } func TestGistsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Gist{ @@ -278,12 +287,15 @@ func TestGistsService_Edit(t *testing.T) { } func TestGistsService_Edit_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Edit(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -316,8 +328,8 @@ func TestGistsService_ListCommits(t *testing.T) { want := []*GistCommit{{ URL: String("https://api.github.com/gists/1/1"), Version: String("1"), - User: &User{ID: Int(1)}, - CommittedAt: &Timestamp{time.Date(2010, 1, 1, 00, 00, 00, 0, time.UTC)}, + User: &User{ID: Int64(1)}, + CommittedAt: &Timestamp{time.Date(2010, time.January, 1, 00, 00, 00, 0, time.UTC)}, ChangeStatus: &CommitStats{ Additions: Int(180), Deletions: Int(0), @@ -330,7 +342,7 @@ func TestGistsService_ListCommits(t *testing.T) { } func TestGistsService_ListCommits_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -348,7 +360,7 @@ func TestGistsService_ListCommits_withOptions(t *testing.T) { } func TestGistsService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { @@ -362,12 +374,15 @@ func TestGistsService_Delete(t *testing.T) { } func TestGistsService_Delete_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Delete(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Star(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -381,12 +396,15 @@ func TestGistsService_Star(t *testing.T) { } func TestGistsService_Star_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Star(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Unstar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -400,12 +418,15 @@ func TestGistsService_Unstar(t *testing.T) { } func TestGistsService_Unstar_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Unstar(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_IsStarred_hasStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -423,7 +444,7 @@ func TestGistsService_IsStarred_hasStar(t *testing.T) { } func TestGistsService_IsStarred_noStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -441,12 +462,15 @@ func TestGistsService_IsStarred_noStar(t *testing.T) { } func TestGistsService_IsStarred_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.IsStarred(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Fork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) { @@ -466,7 +490,7 @@ func TestGistsService_Fork(t *testing.T) { } func TestGistsService_ListForks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) { @@ -492,9 +516,9 @@ func TestGistsService_ListForks(t *testing.T) { want := []*GistFork{{ URL: String("https://api.github.com/gists/1"), ID: String("1"), - User: &User{ID: Int(1)}, - CreatedAt: &Timestamp{time.Date(2010, 1, 1, 00, 00, 00, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2013, 1, 1, 00, 00, 00, 0, time.UTC)}}} + User: &User{ID: Int64(1)}, + CreatedAt: &Timestamp{time.Date(2010, time.January, 1, 00, 00, 00, 0, time.UTC)}, + UpdatedAt: &Timestamp{time.Date(2013, time.January, 1, 00, 00, 00, 0, time.UTC)}}} if !reflect.DeepEqual(gistForks, want) { t.Errorf("Gists.ListForks returned %+v, want %+v", gistForks, want) @@ -502,6 +526,9 @@ func TestGistsService_ListForks(t *testing.T) { } func TestGistsService_Fork_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Fork(context.Background(), "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/git_blobs.go b/vendor/github.com/google/go-github/github/git_blobs.go index 67ea74a19..70aee14a7 100644 --- a/vendor/github.com/google/go-github/github/git_blobs.go +++ b/vendor/github.com/google/go-github/github/git_blobs.go @@ -6,6 +6,7 @@ package github import ( + "bytes" "context" "fmt" ) @@ -17,9 +18,10 @@ type Blob struct { SHA *string `json:"sha,omitempty"` Size *int `json:"size,omitempty"` URL *string `json:"url,omitempty"` + NodeID *string `json:"node_id,omitempty"` } -// GetBlob fetchs a blob from a repo given a SHA. +// GetBlob fetches a blob from a repo given a SHA. // // GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha string) (*Blob, *Response, error) { @@ -34,6 +36,23 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha return blob, resp, err } +// GetBlobRaw fetches a blob's contents from a repo. +// Unlike GetBlob, it returns the raw bytes rather than the base64-encoded data. +// +// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob +func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([]byte, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + req.Header.Set("Accept", "application/vnd.github.v3.raw") + + var buf bytes.Buffer + resp, err := s.client.Do(ctx, req, &buf) + return buf.Bytes(), resp, err +} + // CreateBlob creates a blob object. // // GitHub API docs: https://developer.github.com/v3/git/blobs/#create-a-blob diff --git a/vendor/github.com/google/go-github/github/git_blobs_test.go b/vendor/github.com/google/go-github/github/git_blobs_test.go index 00861bb9a..9945d352e 100644 --- a/vendor/github.com/google/go-github/github/git_blobs_test.go +++ b/vendor/github.com/google/go-github/github/git_blobs_test.go @@ -6,6 +6,7 @@ package github import ( + "bytes" "context" "encoding/json" "fmt" @@ -15,13 +16,12 @@ import ( ) func TestGitService_GetBlob(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/blobs/s", func(w http.ResponseWriter, r *http.Request) { - if m := "GET"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "GET") + fmt.Fprint(w, `{ "sha": "s", "content": "blob content" @@ -44,12 +44,37 @@ func TestGitService_GetBlob(t *testing.T) { } func TestGitService_GetBlob_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetBlob(context.Background(), "%", "%", "%") testURLParseError(t, err) } +func TestGitService_GetBlobRaw(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/git/blobs/s", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", "application/vnd.github.v3.raw") + + fmt.Fprint(w, `raw contents here`) + }) + + blob, _, err := client.Git.GetBlobRaw(context.Background(), "o", "r", "s") + if err != nil { + t.Errorf("Git.GetBlobRaw returned error: %v", err) + } + + want := []byte("raw contents here") + if !bytes.Equal(blob, want) { + t.Errorf("GetBlobRaw returned %q, want %q", blob, want) + } +} + func TestGitService_CreateBlob(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Blob{ @@ -63,9 +88,7 @@ func TestGitService_CreateBlob(t *testing.T) { v := new(Blob) json.NewDecoder(r.Body).Decode(v) - if m := "POST"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "POST") want := input if !reflect.DeepEqual(v, want) { @@ -93,6 +116,9 @@ func TestGitService_CreateBlob(t *testing.T) { } func TestGitService_CreateBlob_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateBlob(context.Background(), "%", "%", &Blob{}) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/git_commits.go b/vendor/github.com/google/go-github/github/git_commits.go index 3c49a8a29..a2b17fcc3 100644 --- a/vendor/github.com/google/go-github/github/git_commits.go +++ b/vendor/github.com/google/go-github/github/git_commits.go @@ -31,6 +31,7 @@ type Commit struct { HTMLURL *string `json:"html_url,omitempty"` URL *string `json:"url,omitempty"` Verification *SignatureVerification `json:"verification,omitempty"` + NodeID *string `json:"node_id,omitempty"` // CommentCount is the number of GitHub comments on the commit. This // is only populated for requests that fetch GitHub data like @@ -57,7 +58,7 @@ func (c CommitAuthor) String() string { return Stringify(c) } -// GetCommit fetchs the Commit object for a given SHA. +// GetCommit fetches the Commit object for a given SHA. // // GitHub API docs: https://developer.github.com/v3/git/commits/#get-a-commit func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, sha string) (*Commit, *Response, error) { @@ -67,7 +68,7 @@ func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, s return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeGitSigningPreview) c := new(Commit) diff --git a/vendor/github.com/google/go-github/github/git_commits_test.go b/vendor/github.com/google/go-github/github/git_commits_test.go index cd392329e..ff8827f90 100644 --- a/vendor/github.com/google/go-github/github/git_commits_test.go +++ b/vendor/github.com/google/go-github/github/git_commits_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/commits/s", func(w http.ResponseWriter, r *http.Request) { @@ -36,12 +36,15 @@ func TestGitService_GetCommit(t *testing.T) { } func TestGitService_GetCommit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetCommit(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestGitService_CreateCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Commit{ @@ -79,6 +82,9 @@ func TestGitService_CreateCommit(t *testing.T) { } func TestGitService_CreateCommit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateCommit(context.Background(), "%", "%", &Commit{}) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/git_refs.go b/vendor/github.com/google/go-github/github/git_refs.go index e78fdc6c0..3b2ced233 100644 --- a/vendor/github.com/google/go-github/github/git_refs.go +++ b/vendor/github.com/google/go-github/github/git_refs.go @@ -18,6 +18,7 @@ type Reference struct { Ref *string `json:"ref"` URL *string `json:"url"` Object *GitObject `json:"object"` + NodeID *string `json:"node_id,omitempty"` } func (r Reference) String() string { diff --git a/vendor/github.com/google/go-github/github/git_refs_test.go b/vendor/github.com/google/go-github/github/git_refs_test.go index 62025bf44..3cae3c085 100644 --- a/vendor/github.com/google/go-github/github/git_refs_test.go +++ b/vendor/github.com/google/go-github/github/git_refs_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetRef_singleRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func TestGitService_GetRef_singleRef(t *testing.T) { } func TestGitService_GetRef_multipleRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -95,7 +95,7 @@ func TestGitService_GetRef_multipleRefs(t *testing.T) { } func TestGitService_GetRefs_singleRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -138,7 +138,7 @@ func TestGitService_GetRefs_singleRef(t *testing.T) { } func TestGitService_GetRefs_multipleRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -188,7 +188,7 @@ func TestGitService_GetRefs_multipleRefs(t *testing.T) { // TestGitService_GetRefs_noRefs tests for behaviour resulting from an unexpected GH response. This should never actually happen. func TestGitService_GetRefs_noRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -205,7 +205,7 @@ func TestGitService_GetRefs_noRefs(t *testing.T) { } func TestGitService_ListRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs", func(w http.ResponseWriter, r *http.Request) { @@ -264,7 +264,7 @@ func TestGitService_ListRefs(t *testing.T) { } func TestGitService_ListRefs_options(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/t", func(w http.ResponseWriter, r *http.Request) { @@ -286,7 +286,7 @@ func TestGitService_ListRefs_options(t *testing.T) { } func TestGitService_CreateRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() args := &createRefRequest{ @@ -350,7 +350,7 @@ func TestGitService_CreateRef(t *testing.T) { } func TestGitService_UpdateRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() args := &updateRefRequest{ @@ -410,7 +410,7 @@ func TestGitService_UpdateRef(t *testing.T) { } func TestGitService_DeleteRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/git_tags.go b/vendor/github.com/google/go-github/github/git_tags.go index 08df3d3d1..f66e4028f 100644 --- a/vendor/github.com/google/go-github/github/git_tags.go +++ b/vendor/github.com/google/go-github/github/git_tags.go @@ -19,6 +19,7 @@ type Tag struct { Tagger *CommitAuthor `json:"tagger,omitempty"` Object *GitObject `json:"object,omitempty"` Verification *SignatureVerification `json:"verification,omitempty"` + NodeID *string `json:"node_id,omitempty"` } // createTagRequest represents the body of a CreateTag request. This is mostly @@ -32,7 +33,7 @@ type createTagRequest struct { Tagger *CommitAuthor `json:"tagger,omitempty"` } -// GetTag fetchs a tag from a repo given a SHA. +// GetTag fetches a tag from a repo given a SHA. // // GitHub API docs: https://developer.github.com/v3/git/tags/#get-a-tag func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha string) (*Tag, *Response, error) { @@ -42,7 +43,7 @@ func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeGitSigningPreview) tag := new(Tag) diff --git a/vendor/github.com/google/go-github/github/git_tags_test.go b/vendor/github.com/google/go-github/github/git_tags_test.go index 7031fe8a4..0b11c64ca 100644 --- a/vendor/github.com/google/go-github/github/git_tags_test.go +++ b/vendor/github.com/google/go-github/github/git_tags_test.go @@ -15,13 +15,12 @@ import ( ) func TestGitService_GetTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/tags/s", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", mediaTypeGitSigningPreview) - fmt.Fprint(w, `{"tag": "t"}`) }) @@ -37,7 +36,7 @@ func TestGitService_GetTag(t *testing.T) { } func TestGitService_CreateTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &createTagRequest{Tag: String("t"), Object: String("s")} diff --git a/vendor/github.com/google/go-github/github/git_trees.go b/vendor/github.com/google/go-github/github/git_trees.go index 4d6809a88..4bc291354 100644 --- a/vendor/github.com/google/go-github/github/git_trees.go +++ b/vendor/github.com/google/go-github/github/git_trees.go @@ -14,6 +14,12 @@ import ( type Tree struct { SHA *string `json:"sha,omitempty"` Entries []TreeEntry `json:"tree,omitempty"` + + // Truncated is true if the number of items in the tree + // exceeded GitHub's maximum limit and the Entries were truncated + // in the response. Only populated for requests that fetch + // trees like Git.GetTree. + Truncated *bool `json:"truncated,omitempty"` } func (t Tree) String() string { diff --git a/vendor/github.com/google/go-github/github/git_trees_test.go b/vendor/github.com/google/go-github/github/git_trees_test.go index 29728eee3..1f7024fc0 100644 --- a/vendor/github.com/google/go-github/github/git_trees_test.go +++ b/vendor/github.com/google/go-github/github/git_trees_test.go @@ -15,16 +15,15 @@ import ( ) func TestGitService_GetTree(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/trees/s", func(w http.ResponseWriter, r *http.Request) { - if m := "GET"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "GET") fmt.Fprint(w, `{ "sha": "s", - "tree": [ { "type": "blob" } ] + "tree": [ { "type": "blob" } ], + "truncated": true }`) }) @@ -40,6 +39,7 @@ func TestGitService_GetTree(t *testing.T) { Type: String("blob"), }, }, + Truncated: Bool(true), } if !reflect.DeepEqual(*tree, want) { t.Errorf("Tree.Get returned %+v, want %+v", *tree, want) @@ -47,12 +47,15 @@ func TestGitService_GetTree(t *testing.T) { } func TestGitService_GetTree_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetTree(context.Background(), "%", "%", "%", false) testURLParseError(t, err) } func TestGitService_CreateTree(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []TreeEntry{ @@ -68,9 +71,7 @@ func TestGitService_CreateTree(t *testing.T) { v := new(createTree) json.NewDecoder(r.Body).Decode(v) - if m := "POST"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "POST") want := &createTree{ BaseTree: "b", @@ -110,6 +111,7 @@ func TestGitService_CreateTree(t *testing.T) { SHA: String("7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"), }, }, + nil, } if !reflect.DeepEqual(*tree, want) { @@ -118,7 +120,7 @@ func TestGitService_CreateTree(t *testing.T) { } func TestGitService_CreateTree_Content(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []TreeEntry{ @@ -133,9 +135,7 @@ func TestGitService_CreateTree_Content(t *testing.T) { v := new(createTree) json.NewDecoder(r.Body).Decode(v) - if m := "POST"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "POST") want := &createTree{ BaseTree: "b", @@ -178,6 +178,7 @@ func TestGitService_CreateTree_Content(t *testing.T) { URL: String("https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b"), }, }, + nil, } if !reflect.DeepEqual(*tree, want) { @@ -186,6 +187,9 @@ func TestGitService_CreateTree_Content(t *testing.T) { } func TestGitService_CreateTree_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateTree(context.Background(), "%", "%", "", nil) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/github-accessors.go b/vendor/github.com/google/go-github/github/github-accessors.go index 6da009baf..1c461b557 100644 --- a/vendor/github.com/google/go-github/github/github-accessors.go +++ b/vendor/github.com/google/go-github/github/github-accessors.go @@ -28,6 +28,86 @@ func (a *AdminEnforcement) GetURL() string { return *a.URL } +// GetComments returns the Comments field. +func (a *AdminStats) GetComments() *CommentStats { + if a == nil { + return nil + } + return a.Comments +} + +// GetGists returns the Gists field. +func (a *AdminStats) GetGists() *GistStats { + if a == nil { + return nil + } + return a.Gists +} + +// GetHooks returns the Hooks field. +func (a *AdminStats) GetHooks() *HookStats { + if a == nil { + return nil + } + return a.Hooks +} + +// GetIssues returns the Issues field. +func (a *AdminStats) GetIssues() *IssueStats { + if a == nil { + return nil + } + return a.Issues +} + +// GetMilestones returns the Milestones field. +func (a *AdminStats) GetMilestones() *MilestoneStats { + if a == nil { + return nil + } + return a.Milestones +} + +// GetOrgs returns the Orgs field. +func (a *AdminStats) GetOrgs() *OrgStats { + if a == nil { + return nil + } + return a.Orgs +} + +// GetPages returns the Pages field. +func (a *AdminStats) GetPages() *PageStats { + if a == nil { + return nil + } + return a.Pages +} + +// GetPulls returns the Pulls field. +func (a *AdminStats) GetPulls() *PullStats { + if a == nil { + return nil + } + return a.Pulls +} + +// GetRepos returns the Repos field. +func (a *AdminStats) GetRepos() *RepoStats { + if a == nil { + return nil + } + return a.Repos +} + +// GetUsers returns the Users field. +func (a *AdminStats) GetUsers() *UserStats { + if a == nil { + return nil + } + return a.Users +} + // GetVerifiablePasswordAuthentication returns the VerifiablePasswordAuthentication field if it's non-nil, zero value otherwise. func (a *APIMeta) GetVerifiablePasswordAuthentication() bool { if a == nil || a.VerifiablePasswordAuthentication == nil { @@ -36,6 +116,86 @@ func (a *APIMeta) GetVerifiablePasswordAuthentication() bool { return *a.VerifiablePasswordAuthentication } +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (a *App) GetCreatedAt() time.Time { + if a == nil || a.CreatedAt == nil { + return time.Time{} + } + return *a.CreatedAt +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (a *App) GetDescription() string { + if a == nil || a.Description == nil { + return "" + } + return *a.Description +} + +// GetExternalURL returns the ExternalURL field if it's non-nil, zero value otherwise. +func (a *App) GetExternalURL() string { + if a == nil || a.ExternalURL == nil { + return "" + } + return *a.ExternalURL +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (a *App) GetHTMLURL() string { + if a == nil || a.HTMLURL == nil { + return "" + } + return *a.HTMLURL +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (a *App) GetID() int64 { + if a == nil || a.ID == nil { + return 0 + } + return *a.ID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (a *App) GetName() string { + if a == nil || a.Name == nil { + return "" + } + return *a.Name +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (a *App) GetNodeID() string { + if a == nil || a.NodeID == nil { + return "" + } + return *a.NodeID +} + +// GetOwner returns the Owner field. +func (a *App) GetOwner() *User { + if a == nil { + return nil + } + return a.Owner +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (a *App) GetUpdatedAt() time.Time { + if a == nil || a.UpdatedAt == nil { + return time.Time{} + } + return *a.UpdatedAt +} + +// GetApp returns the App field. +func (a *Authorization) GetApp() *AuthorizationApp { + if a == nil { + return nil + } + return a.App +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (a *Authorization) GetCreatedAt() Timestamp { if a == nil || a.CreatedAt == nil { @@ -61,7 +221,7 @@ func (a *Authorization) GetHashedToken() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (a *Authorization) GetID() int { +func (a *Authorization) GetID() int64 { if a == nil || a.ID == nil { return 0 } @@ -116,6 +276,14 @@ func (a *Authorization) GetURL() string { return *a.URL } +// GetUser returns the User field. +func (a *Authorization) GetUser() *User { + if a == nil { + return nil + } + return a.User +} + // GetClientID returns the ClientID field if it's non-nil, zero value otherwise. func (a *AuthorizationApp) GetClientID() string { if a == nil || a.ClientID == nil { @@ -204,6 +372,22 @@ func (a *AuthorizationUpdateRequest) GetNoteURL() string { return *a.NoteURL } +// GetAppID returns the AppID field if it's non-nil, zero value otherwise. +func (a *AutoTriggerCheck) GetAppID() int64 { + if a == nil || a.AppID == nil { + return 0 + } + return *a.AppID +} + +// GetSetting returns the Setting field if it's non-nil, zero value otherwise. +func (a *AutoTriggerCheck) GetSetting() bool { + if a == nil || a.Setting == nil { + return false + } + return *a.Setting +} + // GetContent returns the Content field if it's non-nil, zero value otherwise. func (b *Blob) GetContent() string { if b == nil || b.Content == nil { @@ -220,6 +404,14 @@ func (b *Blob) GetEncoding() string { return *b.Encoding } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (b *Blob) GetNodeID() string { + if b == nil || b.NodeID == nil { + return "" + } + return *b.NodeID +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (b *Blob) GetSHA() string { if b == nil || b.SHA == nil { @@ -244,6 +436,14 @@ func (b *Blob) GetURL() string { return *b.URL } +// GetCommit returns the Commit field. +func (b *Branch) GetCommit() *RepositoryCommit { + if b == nil { + return nil + } + return b.Commit +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (b *Branch) GetName() string { if b == nil || b.Name == nil { @@ -260,6 +460,470 @@ func (b *Branch) GetProtected() bool { return *b.Protected } +// GetApp returns the App field. +func (c *CheckRun) GetApp() *App { + if c == nil { + return nil + } + return c.App +} + +// GetCheckSuite returns the CheckSuite field. +func (c *CheckRun) GetCheckSuite() *CheckSuite { + if c == nil { + return nil + } + return c.CheckSuite +} + +// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetCompletedAt() Timestamp { + if c == nil || c.CompletedAt == nil { + return Timestamp{} + } + return *c.CompletedAt +} + +// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetConclusion() string { + if c == nil || c.Conclusion == nil { + return "" + } + return *c.Conclusion +} + +// GetDetailsURL returns the DetailsURL field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetDetailsURL() string { + if c == nil || c.DetailsURL == nil { + return "" + } + return *c.DetailsURL +} + +// GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetExternalID() string { + if c == nil || c.ExternalID == nil { + return "" + } + return *c.ExternalID +} + +// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetHeadSHA() string { + if c == nil || c.HeadSHA == nil { + return "" + } + return *c.HeadSHA +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { + return "" + } + return *c.HTMLURL +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetID() int64 { + if c == nil || c.ID == nil { + return 0 + } + return *c.ID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetName() string { + if c == nil || c.Name == nil { + return "" + } + return *c.Name +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetNodeID() string { + if c == nil || c.NodeID == nil { + return "" + } + return *c.NodeID +} + +// GetOutput returns the Output field. +func (c *CheckRun) GetOutput() *CheckRunOutput { + if c == nil { + return nil + } + return c.Output +} + +// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetStartedAt() Timestamp { + if c == nil || c.StartedAt == nil { + return Timestamp{} + } + return *c.StartedAt +} + +// GetStatus returns the Status field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetStatus() string { + if c == nil || c.Status == nil { + return "" + } + return *c.Status +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CheckRun) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + +// GetAnnotationLevel returns the AnnotationLevel field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetAnnotationLevel() string { + if c == nil || c.AnnotationLevel == nil { + return "" + } + return *c.AnnotationLevel +} + +// GetBlobHRef returns the BlobHRef field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetBlobHRef() string { + if c == nil || c.BlobHRef == nil { + return "" + } + return *c.BlobHRef +} + +// GetEndLine returns the EndLine field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetEndLine() int { + if c == nil || c.EndLine == nil { + return 0 + } + return *c.EndLine +} + +// GetMessage returns the Message field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetMessage() string { + if c == nil || c.Message == nil { + return "" + } + return *c.Message +} + +// GetPath returns the Path field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetPath() string { + if c == nil || c.Path == nil { + return "" + } + return *c.Path +} + +// GetRawDetails returns the RawDetails field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetRawDetails() string { + if c == nil || c.RawDetails == nil { + return "" + } + return *c.RawDetails +} + +// GetStartLine returns the StartLine field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetStartLine() int { + if c == nil || c.StartLine == nil { + return 0 + } + return *c.StartLine +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *CheckRunAnnotation) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (c *CheckRunEvent) GetAction() string { + if c == nil || c.Action == nil { + return "" + } + return *c.Action +} + +// GetCheckRun returns the CheckRun field. +func (c *CheckRunEvent) GetCheckRun() *CheckRun { + if c == nil { + return nil + } + return c.CheckRun +} + +// GetInstallation returns the Installation field. +func (c *CheckRunEvent) GetInstallation() *Installation { + if c == nil { + return nil + } + return c.Installation +} + +// GetOrg returns the Org field. +func (c *CheckRunEvent) GetOrg() *Organization { + if c == nil { + return nil + } + return c.Org +} + +// GetRepo returns the Repo field. +func (c *CheckRunEvent) GetRepo() *Repository { + if c == nil { + return nil + } + return c.Repo +} + +// GetRequestedAction returns the RequestedAction field. +func (c *CheckRunEvent) GetRequestedAction() *RequestedAction { + if c == nil { + return nil + } + return c.RequestedAction +} + +// GetSender returns the Sender field. +func (c *CheckRunEvent) GetSender() *User { + if c == nil { + return nil + } + return c.Sender +} + +// GetAlt returns the Alt field if it's non-nil, zero value otherwise. +func (c *CheckRunImage) GetAlt() string { + if c == nil || c.Alt == nil { + return "" + } + return *c.Alt +} + +// GetCaption returns the Caption field if it's non-nil, zero value otherwise. +func (c *CheckRunImage) GetCaption() string { + if c == nil || c.Caption == nil { + return "" + } + return *c.Caption +} + +// GetImageURL returns the ImageURL field if it's non-nil, zero value otherwise. +func (c *CheckRunImage) GetImageURL() string { + if c == nil || c.ImageURL == nil { + return "" + } + return *c.ImageURL +} + +// GetAnnotationsCount returns the AnnotationsCount field if it's non-nil, zero value otherwise. +func (c *CheckRunOutput) GetAnnotationsCount() int { + if c == nil || c.AnnotationsCount == nil { + return 0 + } + return *c.AnnotationsCount +} + +// GetAnnotationsURL returns the AnnotationsURL field if it's non-nil, zero value otherwise. +func (c *CheckRunOutput) GetAnnotationsURL() string { + if c == nil || c.AnnotationsURL == nil { + return "" + } + return *c.AnnotationsURL +} + +// GetSummary returns the Summary field if it's non-nil, zero value otherwise. +func (c *CheckRunOutput) GetSummary() string { + if c == nil || c.Summary == nil { + return "" + } + return *c.Summary +} + +// GetText returns the Text field if it's non-nil, zero value otherwise. +func (c *CheckRunOutput) GetText() string { + if c == nil || c.Text == nil { + return "" + } + return *c.Text +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *CheckRunOutput) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + +// GetAfterSHA returns the AfterSHA field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetAfterSHA() string { + if c == nil || c.AfterSHA == nil { + return "" + } + return *c.AfterSHA +} + +// GetApp returns the App field. +func (c *CheckSuite) GetApp() *App { + if c == nil { + return nil + } + return c.App +} + +// GetBeforeSHA returns the BeforeSHA field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetBeforeSHA() string { + if c == nil || c.BeforeSHA == nil { + return "" + } + return *c.BeforeSHA +} + +// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetConclusion() string { + if c == nil || c.Conclusion == nil { + return "" + } + return *c.Conclusion +} + +// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetHeadBranch() string { + if c == nil || c.HeadBranch == nil { + return "" + } + return *c.HeadBranch +} + +// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetHeadSHA() string { + if c == nil || c.HeadSHA == nil { + return "" + } + return *c.HeadSHA +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetID() int64 { + if c == nil || c.ID == nil { + return 0 + } + return *c.ID +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetNodeID() string { + if c == nil || c.NodeID == nil { + return "" + } + return *c.NodeID +} + +// GetRepository returns the Repository field. +func (c *CheckSuite) GetRepository() *Repository { + if c == nil { + return nil + } + return c.Repository +} + +// GetStatus returns the Status field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetStatus() string { + if c == nil || c.Status == nil { + return "" + } + return *c.Status +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (c *CheckSuiteEvent) GetAction() string { + if c == nil || c.Action == nil { + return "" + } + return *c.Action +} + +// GetCheckSuite returns the CheckSuite field. +func (c *CheckSuiteEvent) GetCheckSuite() *CheckSuite { + if c == nil { + return nil + } + return c.CheckSuite +} + +// GetInstallation returns the Installation field. +func (c *CheckSuiteEvent) GetInstallation() *Installation { + if c == nil { + return nil + } + return c.Installation +} + +// GetOrg returns the Org field. +func (c *CheckSuiteEvent) GetOrg() *Organization { + if c == nil { + return nil + } + return c.Org +} + +// GetRepo returns the Repo field. +func (c *CheckSuiteEvent) GetRepo() *Repository { + if c == nil { + return nil + } + return c.Repo +} + +// GetSender returns the Sender field. +func (c *CheckSuiteEvent) GetSender() *User { + if c == nil { + return nil + } + return c.Sender +} + +// GetPreferenceList returns the PreferenceList field. +func (c *CheckSuitePreferenceOptions) GetPreferenceList() *PreferenceList { + if c == nil { + return nil + } + return c.PreferenceList +} + +// GetPreferences returns the Preferences field. +func (c *CheckSuitePreferenceResults) GetPreferences() *PreferenceList { + if c == nil { + return nil + } + return c.Preferences +} + +// GetRepository returns the Repository field. +func (c *CheckSuitePreferenceResults) GetRepository() *Repository { + if c == nil { + return nil + } + return c.Repository +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (c *CodeOfConduct) GetBody() string { if c == nil || c.Body == nil { @@ -316,6 +980,14 @@ func (c *CodeResult) GetPath() string { return *c.Path } +// GetRepository returns the Repository field. +func (c *CodeResult) GetRepository() *Repository { + if c == nil { + return nil + } + return c.Repository +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (c *CodeResult) GetSHA() string { if c == nil || c.SHA == nil { @@ -388,6 +1060,46 @@ func (c *CombinedStatus) GetTotalCount() int { return *c.TotalCount } +// GetTotalCommitComments returns the TotalCommitComments field if it's non-nil, zero value otherwise. +func (c *CommentStats) GetTotalCommitComments() int { + if c == nil || c.TotalCommitComments == nil { + return 0 + } + return *c.TotalCommitComments +} + +// GetTotalGistComments returns the TotalGistComments field if it's non-nil, zero value otherwise. +func (c *CommentStats) GetTotalGistComments() int { + if c == nil || c.TotalGistComments == nil { + return 0 + } + return *c.TotalGistComments +} + +// GetTotalIssueComments returns the TotalIssueComments field if it's non-nil, zero value otherwise. +func (c *CommentStats) GetTotalIssueComments() int { + if c == nil || c.TotalIssueComments == nil { + return 0 + } + return *c.TotalIssueComments +} + +// GetTotalPullRequestComments returns the TotalPullRequestComments field if it's non-nil, zero value otherwise. +func (c *CommentStats) GetTotalPullRequestComments() int { + if c == nil || c.TotalPullRequestComments == nil { + return 0 + } + return *c.TotalPullRequestComments +} + +// GetAuthor returns the Author field. +func (c *Commit) GetAuthor() *CommitAuthor { + if c == nil { + return nil + } + return c.Author +} + // GetCommentCount returns the CommentCount field if it's non-nil, zero value otherwise. func (c *Commit) GetCommentCount() int { if c == nil || c.CommentCount == nil { @@ -396,6 +1108,14 @@ func (c *Commit) GetCommentCount() int { return *c.CommentCount } +// GetCommitter returns the Committer field. +func (c *Commit) GetCommitter() *CommitAuthor { + if c == nil { + return nil + } + return c.Committer +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (c *Commit) GetHTMLURL() string { if c == nil || c.HTMLURL == nil { @@ -412,6 +1132,14 @@ func (c *Commit) GetMessage() string { return *c.Message } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (c *Commit) GetNodeID() string { + if c == nil || c.NodeID == nil { + return "" + } + return *c.NodeID +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (c *Commit) GetSHA() string { if c == nil || c.SHA == nil { @@ -420,6 +1148,22 @@ func (c *Commit) GetSHA() string { return *c.SHA } +// GetStats returns the Stats field. +func (c *Commit) GetStats() *CommitStats { + if c == nil { + return nil + } + return c.Stats +} + +// GetTree returns the Tree field. +func (c *Commit) GetTree() *Tree { + if c == nil { + return nil + } + return c.Tree +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (c *Commit) GetURL() string { if c == nil || c.URL == nil { @@ -428,6 +1172,14 @@ func (c *Commit) GetURL() string { return *c.URL } +// GetVerification returns the Verification field. +func (c *Commit) GetVerification() *SignatureVerification { + if c == nil { + return nil + } + return c.Verification +} + // GetDate returns the Date field if it's non-nil, zero value otherwise. func (c *CommitAuthor) GetDate() time.Time { if c == nil || c.Date == nil { @@ -468,6 +1220,38 @@ func (c *CommitCommentEvent) GetAction() string { return *c.Action } +// GetComment returns the Comment field. +func (c *CommitCommentEvent) GetComment() *RepositoryComment { + if c == nil { + return nil + } + return c.Comment +} + +// GetInstallation returns the Installation field. +func (c *CommitCommentEvent) GetInstallation() *Installation { + if c == nil { + return nil + } + return c.Installation +} + +// GetRepo returns the Repo field. +func (c *CommitCommentEvent) GetRepo() *Repository { + if c == nil { + return nil + } + return c.Repo +} + +// GetSender returns the Sender field. +func (c *CommitCommentEvent) GetSender() *User { + if c == nil { + return nil + } + return c.Sender +} + // GetAdditions returns the Additions field if it's non-nil, zero value otherwise. func (c *CommitFile) GetAdditions() int { if c == nil || c.Additions == nil { @@ -524,6 +1308,14 @@ func (c *CommitFile) GetPatch() string { return *c.Patch } +// GetPreviousFilename returns the PreviousFilename field if it's non-nil, zero value otherwise. +func (c *CommitFile) GetPreviousFilename() string { + if c == nil || c.PreviousFilename == nil { + return "" + } + return *c.PreviousFilename +} + // GetRawURL returns the RawURL field if it's non-nil, zero value otherwise. func (c *CommitFile) GetRawURL() string { if c == nil || c.RawURL == nil { @@ -548,6 +1340,14 @@ func (c *CommitFile) GetStatus() string { return *c.Status } +// GetAuthor returns the Author field. +func (c *CommitResult) GetAuthor() *User { + if c == nil { + return nil + } + return c.Author +} + // GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. func (c *CommitResult) GetCommentsURL() string { if c == nil || c.CommentsURL == nil { @@ -556,6 +1356,22 @@ func (c *CommitResult) GetCommentsURL() string { return *c.CommentsURL } +// GetCommit returns the Commit field. +func (c *CommitResult) GetCommit() *Commit { + if c == nil { + return nil + } + return c.Commit +} + +// GetCommitter returns the Committer field. +func (c *CommitResult) GetCommitter() *User { + if c == nil { + return nil + } + return c.Committer +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (c *CommitResult) GetHTMLURL() string { if c == nil || c.HTMLURL == nil { @@ -564,6 +1380,22 @@ func (c *CommitResult) GetHTMLURL() string { return *c.HTMLURL } +// GetRepository returns the Repository field. +func (c *CommitResult) GetRepository() *Repository { + if c == nil { + return nil + } + return c.Repository +} + +// GetScore returns the Score field. +func (c *CommitResult) GetScore() *float64 { + if c == nil { + return nil + } + return c.Score +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (c *CommitResult) GetSHA() string { if c == nil || c.SHA == nil { @@ -588,6 +1420,14 @@ func (c *CommitsComparison) GetAheadBy() int { return *c.AheadBy } +// GetBaseCommit returns the BaseCommit field. +func (c *CommitsComparison) GetBaseCommit() *RepositoryCommit { + if c == nil { + return nil + } + return c.BaseCommit +} + // GetBehindBy returns the BehindBy field if it's non-nil, zero value otherwise. func (c *CommitsComparison) GetBehindBy() int { if c == nil || c.BehindBy == nil { @@ -612,6 +1452,14 @@ func (c *CommitsComparison) GetHTMLURL() string { return *c.HTMLURL } +// GetMergeBaseCommit returns the MergeBaseCommit field. +func (c *CommitsComparison) GetMergeBaseCommit() *RepositoryCommit { + if c == nil { + return nil + } + return c.MergeBaseCommit +} + // GetPatchURL returns the PatchURL field if it's non-nil, zero value otherwise. func (c *CommitsComparison) GetPatchURL() string { if c == nil || c.PatchURL == nil { @@ -692,6 +1540,62 @@ func (c *CommitStats) GetTotal() int { return *c.Total } +// GetCodeOfConduct returns the CodeOfConduct field. +func (c *CommunityHealthFiles) GetCodeOfConduct() *Metric { + if c == nil { + return nil + } + return c.CodeOfConduct +} + +// GetContributing returns the Contributing field. +func (c *CommunityHealthFiles) GetContributing() *Metric { + if c == nil { + return nil + } + return c.Contributing +} + +// GetIssueTemplate returns the IssueTemplate field. +func (c *CommunityHealthFiles) GetIssueTemplate() *Metric { + if c == nil { + return nil + } + return c.IssueTemplate +} + +// GetLicense returns the License field. +func (c *CommunityHealthFiles) GetLicense() *Metric { + if c == nil { + return nil + } + return c.License +} + +// GetPullRequestTemplate returns the PullRequestTemplate field. +func (c *CommunityHealthFiles) GetPullRequestTemplate() *Metric { + if c == nil { + return nil + } + return c.PullRequestTemplate +} + +// GetReadme returns the Readme field. +func (c *CommunityHealthFiles) GetReadme() *Metric { + if c == nil { + return nil + } + return c.Readme +} + +// GetFiles returns the Files field. +func (c *CommunityHealthMetrics) GetFiles() *CommunityHealthFiles { + if c == nil { + return nil + } + return c.Files +} + // GetHealthPercentage returns the HealthPercentage field if it's non-nil, zero value otherwise. func (c *CommunityHealthMetrics) GetHealthPercentage() int { if c == nil || c.HealthPercentage == nil { @@ -773,7 +1677,7 @@ func (c *Contributor) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (c *Contributor) GetID() int { +func (c *Contributor) GetID() int64 { if c == nil || c.ID == nil { return 0 } @@ -852,6 +1756,14 @@ func (c *Contributor) GetURL() string { return *c.URL } +// GetAuthor returns the Author field. +func (c *ContributorStats) GetAuthor() *Contributor { + if c == nil { + return nil + } + return c.Author +} + // GetTotal returns the Total field if it's non-nil, zero value otherwise. func (c *ContributorStats) GetTotal() int { if c == nil || c.Total == nil { @@ -860,20 +1772,68 @@ func (c *ContributorStats) GetTotal() int { return *c.Total } -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (c *createCommit) GetMessage() string { - if c == nil || c.Message == nil { - return "" +// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetCompletedAt() Timestamp { + if c == nil || c.CompletedAt == nil { + return Timestamp{} } - return *c.Message + return *c.CompletedAt } -// GetTree returns the Tree field if it's non-nil, zero value otherwise. -func (c *createCommit) GetTree() string { - if c == nil || c.Tree == nil { +// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetConclusion() string { + if c == nil || c.Conclusion == nil { return "" } - return *c.Tree + return *c.Conclusion +} + +// GetDetailsURL returns the DetailsURL field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetDetailsURL() string { + if c == nil || c.DetailsURL == nil { + return "" + } + return *c.DetailsURL +} + +// GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetExternalID() string { + if c == nil || c.ExternalID == nil { + return "" + } + return *c.ExternalID +} + +// GetOutput returns the Output field. +func (c *CreateCheckRunOptions) GetOutput() *CheckRunOutput { + if c == nil { + return nil + } + return c.Output +} + +// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetStartedAt() Timestamp { + if c == nil || c.StartedAt == nil { + return Timestamp{} + } + return *c.StartedAt +} + +// GetStatus returns the Status field if it's non-nil, zero value otherwise. +func (c *CreateCheckRunOptions) GetStatus() string { + if c == nil || c.Status == nil { + return "" + } + return *c.Status +} + +// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. +func (c *CreateCheckSuiteOptions) GetHeadBranch() string { + if c == nil || c.HeadBranch == nil { + return "" + } + return *c.HeadBranch } // GetDescription returns the Description field if it's non-nil, zero value otherwise. @@ -884,6 +1844,14 @@ func (c *CreateEvent) GetDescription() string { return *c.Description } +// GetInstallation returns the Installation field. +func (c *CreateEvent) GetInstallation() *Installation { + if c == nil { + return nil + } + return c.Installation +} + // GetMasterBranch returns the MasterBranch field if it's non-nil, zero value otherwise. func (c *CreateEvent) GetMasterBranch() string { if c == nil || c.MasterBranch == nil { @@ -916,52 +1884,52 @@ func (c *CreateEvent) GetRefType() string { return *c.RefType } -// GetRef returns the Ref field if it's non-nil, zero value otherwise. -func (c *createRefRequest) GetRef() string { - if c == nil || c.Ref == nil { - return "" +// GetRepo returns the Repo field. +func (c *CreateEvent) GetRepo() *Repository { + if c == nil { + return nil } - return *c.Ref + return c.Repo } -// GetSHA returns the SHA field if it's non-nil, zero value otherwise. -func (c *createRefRequest) GetSHA() string { - if c == nil || c.SHA == nil { - return "" +// GetSender returns the Sender field. +func (c *CreateEvent) GetSender() *User { + if c == nil { + return nil } - return *c.SHA + return c.Sender } -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (c *createTagRequest) GetMessage() string { - if c == nil || c.Message == nil { +// GetEmail returns the Email field if it's non-nil, zero value otherwise. +func (c *CreateOrgInvitationOptions) GetEmail() string { + if c == nil || c.Email == nil { return "" } - return *c.Message + return *c.Email } -// GetObject returns the Object field if it's non-nil, zero value otherwise. -func (c *createTagRequest) GetObject() string { - if c == nil || c.Object == nil { - return "" +// GetInviteeID returns the InviteeID field if it's non-nil, zero value otherwise. +func (c *CreateOrgInvitationOptions) GetInviteeID() int64 { + if c == nil || c.InviteeID == nil { + return 0 } - return *c.Object + return *c.InviteeID } -// GetTag returns the Tag field if it's non-nil, zero value otherwise. -func (c *createTagRequest) GetTag() string { - if c == nil || c.Tag == nil { +// GetRole returns the Role field if it's non-nil, zero value otherwise. +func (c *CreateOrgInvitationOptions) GetRole() string { + if c == nil || c.Role == nil { return "" } - return *c.Tag + return *c.Role } -// GetType returns the Type field if it's non-nil, zero value otherwise. -func (c *createTagRequest) GetType() string { - if c == nil || c.Type == nil { - return "" +// GetInstallation returns the Installation field. +func (d *DeleteEvent) GetInstallation() *Installation { + if d == nil { + return nil } - return *c.Type + return d.Installation } // GetPusherType returns the PusherType field if it's non-nil, zero value otherwise. @@ -988,6 +1956,22 @@ func (d *DeleteEvent) GetRefType() string { return *d.RefType } +// GetRepo returns the Repo field. +func (d *DeleteEvent) GetRepo() *Repository { + if d == nil { + return nil + } + return d.Repo +} + +// GetSender returns the Sender field. +func (d *DeleteEvent) GetSender() *User { + if d == nil { + return nil + } + return d.Sender +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (d *Deployment) GetCreatedAt() Timestamp { if d == nil || d.CreatedAt == nil { @@ -996,6 +1980,14 @@ func (d *Deployment) GetCreatedAt() Timestamp { return *d.CreatedAt } +// GetCreator returns the Creator field. +func (d *Deployment) GetCreator() *User { + if d == nil { + return nil + } + return d.Creator +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (d *Deployment) GetDescription() string { if d == nil || d.Description == nil { @@ -1013,13 +2005,21 @@ func (d *Deployment) GetEnvironment() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (d *Deployment) GetID() int { +func (d *Deployment) GetID() int64 { if d == nil || d.ID == nil { return 0 } return *d.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (d *Deployment) GetNodeID() string { + if d == nil || d.NodeID == nil { + return "" + } + return *d.NodeID +} + // GetRef returns the Ref field if it's non-nil, zero value otherwise. func (d *Deployment) GetRef() string { if d == nil || d.Ref == nil { @@ -1076,6 +2076,38 @@ func (d *Deployment) GetURL() string { return *d.URL } +// GetDeployment returns the Deployment field. +func (d *DeploymentEvent) GetDeployment() *Deployment { + if d == nil { + return nil + } + return d.Deployment +} + +// GetInstallation returns the Installation field. +func (d *DeploymentEvent) GetInstallation() *Installation { + if d == nil { + return nil + } + return d.Installation +} + +// GetRepo returns the Repo field. +func (d *DeploymentEvent) GetRepo() *Repository { + if d == nil { + return nil + } + return d.Repo +} + +// GetSender returns the Sender field. +func (d *DeploymentEvent) GetSender() *User { + if d == nil { + return nil + } + return d.Sender +} + // GetAutoMerge returns the AutoMerge field if it's non-nil, zero value otherwise. func (d *DeploymentRequest) GetAutoMerge() bool { if d == nil || d.AutoMerge == nil { @@ -1156,6 +2188,14 @@ func (d *DeploymentStatus) GetCreatedAt() Timestamp { return *d.CreatedAt } +// GetCreator returns the Creator field. +func (d *DeploymentStatus) GetCreator() *User { + if d == nil { + return nil + } + return d.Creator +} + // GetDeploymentURL returns the DeploymentURL field if it's non-nil, zero value otherwise. func (d *DeploymentStatus) GetDeploymentURL() string { if d == nil || d.DeploymentURL == nil { @@ -1173,13 +2213,21 @@ func (d *DeploymentStatus) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (d *DeploymentStatus) GetID() int { +func (d *DeploymentStatus) GetID() int64 { if d == nil || d.ID == nil { return 0 } return *d.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (d *DeploymentStatus) GetNodeID() string { + if d == nil || d.NodeID == nil { + return "" + } + return *d.NodeID +} + // GetRepositoryURL returns the RepositoryURL field if it's non-nil, zero value otherwise. func (d *DeploymentStatus) GetRepositoryURL() string { if d == nil || d.RepositoryURL == nil { @@ -1212,6 +2260,46 @@ func (d *DeploymentStatus) GetUpdatedAt() Timestamp { return *d.UpdatedAt } +// GetDeployment returns the Deployment field. +func (d *DeploymentStatusEvent) GetDeployment() *Deployment { + if d == nil { + return nil + } + return d.Deployment +} + +// GetDeploymentStatus returns the DeploymentStatus field. +func (d *DeploymentStatusEvent) GetDeploymentStatus() *DeploymentStatus { + if d == nil { + return nil + } + return d.DeploymentStatus +} + +// GetInstallation returns the Installation field. +func (d *DeploymentStatusEvent) GetInstallation() *Installation { + if d == nil { + return nil + } + return d.Installation +} + +// GetRepo returns the Repo field. +func (d *DeploymentStatusEvent) GetRepo() *Repository { + if d == nil { + return nil + } + return d.Repo +} + +// GetSender returns the Sender field. +func (d *DeploymentStatusEvent) GetSender() *User { + if d == nil { + return nil + } + return d.Sender +} + // GetAutoInactive returns the AutoInactive field if it's non-nil, zero value otherwise. func (d *DeploymentStatusRequest) GetAutoInactive() bool { if d == nil || d.AutoInactive == nil { @@ -1228,6 +2316,14 @@ func (d *DeploymentStatusRequest) GetDescription() string { return *d.Description } +// GetEnvironment returns the Environment field if it's non-nil, zero value otherwise. +func (d *DeploymentStatusRequest) GetEnvironment() string { + if d == nil || d.Environment == nil { + return "" + } + return *d.Environment +} + // GetEnvironmentURL returns the EnvironmentURL field if it's non-nil, zero value otherwise. func (d *DeploymentStatusRequest) GetEnvironmentURL() string { if d == nil || d.EnvironmentURL == nil { @@ -1252,6 +2348,126 @@ func (d *DeploymentStatusRequest) GetState() string { return *d.State } +// GetAuthor returns the Author field. +func (d *DiscussionComment) GetAuthor() *User { + if d == nil { + return nil + } + return d.Author +} + +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetBody() string { + if d == nil || d.Body == nil { + return "" + } + return *d.Body +} + +// GetBodyHTML returns the BodyHTML field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetBodyHTML() string { + if d == nil || d.BodyHTML == nil { + return "" + } + return *d.BodyHTML +} + +// GetBodyVersion returns the BodyVersion field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetBodyVersion() string { + if d == nil || d.BodyVersion == nil { + return "" + } + return *d.BodyVersion +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetCreatedAt() Timestamp { + if d == nil || d.CreatedAt == nil { + return Timestamp{} + } + return *d.CreatedAt +} + +// GetDiscussionURL returns the DiscussionURL field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetDiscussionURL() string { + if d == nil || d.DiscussionURL == nil { + return "" + } + return *d.DiscussionURL +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetHTMLURL() string { + if d == nil || d.HTMLURL == nil { + return "" + } + return *d.HTMLURL +} + +// GetLastEditedAt returns the LastEditedAt field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetLastEditedAt() Timestamp { + if d == nil || d.LastEditedAt == nil { + return Timestamp{} + } + return *d.LastEditedAt +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetNodeID() string { + if d == nil || d.NodeID == nil { + return "" + } + return *d.NodeID +} + +// GetNumber returns the Number field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetNumber() int { + if d == nil || d.Number == nil { + return 0 + } + return *d.Number +} + +// GetReactions returns the Reactions field. +func (d *DiscussionComment) GetReactions() *Reactions { + if d == nil { + return nil + } + return d.Reactions +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetUpdatedAt() Timestamp { + if d == nil || d.UpdatedAt == nil { + return Timestamp{} + } + return *d.UpdatedAt +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (d *DiscussionComment) GetURL() string { + if d == nil || d.URL == nil { + return "" + } + return *d.URL +} + +// GetTeams returns the Teams field if it's non-nil, zero value otherwise. +func (d *DismissalRestrictionsRequest) GetTeams() []string { + if d == nil || d.Teams == nil { + return nil + } + return *d.Teams +} + +// GetUsers returns the Users field if it's non-nil, zero value otherwise. +func (d *DismissalRestrictionsRequest) GetUsers() []string { + if d == nil || d.Users == nil { + return nil + } + return *d.Users +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (d *DraftReviewComment) GetBody() string { if d == nil || d.Body == nil { @@ -1276,6 +2492,14 @@ func (d *DraftReviewComment) GetPosition() int { return *d.Position } +// GetActor returns the Actor field. +func (e *Event) GetActor() *User { + if e == nil { + return nil + } + return e.Actor +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (e *Event) GetCreatedAt() time.Time { if e == nil || e.CreatedAt == nil { @@ -1292,6 +2516,14 @@ func (e *Event) GetID() string { return *e.ID } +// GetOrg returns the Org field. +func (e *Event) GetOrg() *Organization { + if e == nil { + return nil + } + return e.Org +} + // GetPublic returns the Public field if it's non-nil, zero value otherwise. func (e *Event) GetPublic() bool { if e == nil || e.Public == nil { @@ -1308,6 +2540,14 @@ func (e *Event) GetRawPayload() json.RawMessage { return *e.RawPayload } +// GetRepo returns the Repo field. +func (e *Event) GetRepo() *Repository { + if e == nil { + return nil + } + return e.Repo +} + // GetType returns the Type field if it's non-nil, zero value otherwise. func (e *Event) GetType() string { if e == nil || e.Type == nil { @@ -1380,6 +2620,38 @@ func (f *Feeds) GetUserURL() string { return *f.UserURL } +// GetForkee returns the Forkee field. +func (f *ForkEvent) GetForkee() *Repository { + if f == nil { + return nil + } + return f.Forkee +} + +// GetInstallation returns the Installation field. +func (f *ForkEvent) GetInstallation() *Installation { + if f == nil { + return nil + } + return f.Installation +} + +// GetRepo returns the Repo field. +func (f *ForkEvent) GetRepo() *Repository { + if f == nil { + return nil + } + return f.Repo +} + +// GetSender returns the Sender field. +func (f *ForkEvent) GetSender() *User { + if f == nil { + return nil + } + return f.Sender +} + // GetComments returns the Comments field if it's non-nil, zero value otherwise. func (g *Gist) GetComments() int { if g == nil || g.Comments == nil { @@ -1436,6 +2708,22 @@ func (g *Gist) GetID() string { return *g.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (g *Gist) GetNodeID() string { + if g == nil || g.NodeID == nil { + return "" + } + return *g.NodeID +} + +// GetOwner returns the Owner field. +func (g *Gist) GetOwner() *User { + if g == nil { + return nil + } + return g.Owner +} + // GetPublic returns the Public field if it's non-nil, zero value otherwise. func (g *Gist) GetPublic() bool { if g == nil || g.Public == nil { @@ -1469,7 +2757,7 @@ func (g *GistComment) GetCreatedAt() time.Time { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (g *GistComment) GetID() int { +func (g *GistComment) GetID() int64 { if g == nil || g.ID == nil { return 0 } @@ -1484,6 +2772,22 @@ func (g *GistComment) GetURL() string { return *g.URL } +// GetUser returns the User field. +func (g *GistComment) GetUser() *User { + if g == nil { + return nil + } + return g.User +} + +// GetChangeStatus returns the ChangeStatus field. +func (g *GistCommit) GetChangeStatus() *CommitStats { + if g == nil { + return nil + } + return g.ChangeStatus +} + // GetCommittedAt returns the CommittedAt field if it's non-nil, zero value otherwise. func (g *GistCommit) GetCommittedAt() Timestamp { if g == nil || g.CommittedAt == nil { @@ -1492,6 +2796,14 @@ func (g *GistCommit) GetCommittedAt() Timestamp { return *g.CommittedAt } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (g *GistCommit) GetNodeID() string { + if g == nil || g.NodeID == nil { + return "" + } + return *g.NodeID +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (g *GistCommit) GetURL() string { if g == nil || g.URL == nil { @@ -1500,6 +2812,14 @@ func (g *GistCommit) GetURL() string { return *g.URL } +// GetUser returns the User field. +func (g *GistCommit) GetUser() *User { + if g == nil { + return nil + } + return g.User +} + // GetVersion returns the Version field if it's non-nil, zero value otherwise. func (g *GistCommit) GetVersion() string { if g == nil || g.Version == nil { @@ -1572,6 +2892,14 @@ func (g *GistFork) GetID() string { return *g.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (g *GistFork) GetNodeID() string { + if g == nil || g.NodeID == nil { + return "" + } + return *g.NodeID +} + // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (g *GistFork) GetUpdatedAt() Timestamp { if g == nil || g.UpdatedAt == nil { @@ -1588,6 +2916,54 @@ func (g *GistFork) GetURL() string { return *g.URL } +// GetUser returns the User field. +func (g *GistFork) GetUser() *User { + if g == nil { + return nil + } + return g.User +} + +// GetPrivateGists returns the PrivateGists field if it's non-nil, zero value otherwise. +func (g *GistStats) GetPrivateGists() int { + if g == nil || g.PrivateGists == nil { + return 0 + } + return *g.PrivateGists +} + +// GetPublicGists returns the PublicGists field if it's non-nil, zero value otherwise. +func (g *GistStats) GetPublicGists() int { + if g == nil || g.PublicGists == nil { + return 0 + } + return *g.PublicGists +} + +// GetTotalGists returns the TotalGists field if it's non-nil, zero value otherwise. +func (g *GistStats) GetTotalGists() int { + if g == nil || g.TotalGists == nil { + return 0 + } + return *g.TotalGists +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (g *GitHubAppAuthorizationEvent) GetAction() string { + if g == nil || g.Action == nil { + return "" + } + return *g.Action +} + +// GetSender returns the Sender field. +func (g *GitHubAppAuthorizationEvent) GetSender() *User { + if g == nil { + return nil + } + return g.Sender +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (g *Gitignore) GetName() string { if g == nil || g.Name == nil { @@ -1628,6 +3004,30 @@ func (g *GitObject) GetURL() string { return *g.URL } +// GetInstallation returns the Installation field. +func (g *GollumEvent) GetInstallation() *Installation { + if g == nil { + return nil + } + return g.Installation +} + +// GetRepo returns the Repo field. +func (g *GollumEvent) GetRepo() *Repository { + if g == nil { + return nil + } + return g.Repo +} + +// GetSender returns the Sender field. +func (g *GollumEvent) GetSender() *User { + if g == nil { + return nil + } + return g.Sender +} + // GetEmail returns the Email field if it's non-nil, zero value otherwise. func (g *GPGEmail) GetEmail() string { if g == nil || g.Email == nil { @@ -1693,7 +3093,7 @@ func (g *GPGKey) GetExpiresAt() time.Time { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (g *GPGKey) GetID() int { +func (g *GPGKey) GetID() int64 { if g == nil || g.ID == nil { return 0 } @@ -1709,7 +3109,7 @@ func (g *GPGKey) GetKeyID() string { } // GetPrimaryKeyID returns the PrimaryKeyID field if it's non-nil, zero value otherwise. -func (g *GPGKey) GetPrimaryKeyID() int { +func (g *GPGKey) GetPrimaryKeyID() int64 { if g == nil || g.PrimaryKeyID == nil { return 0 } @@ -1724,6 +3124,14 @@ func (g *GPGKey) GetPublicKey() string { return *g.PublicKey } +// GetApp returns the App field. +func (g *Grant) GetApp() *AuthorizationApp { + if g == nil { + return nil + } + return g.App +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (g *Grant) GetCreatedAt() Timestamp { if g == nil || g.CreatedAt == nil { @@ -1733,7 +3141,7 @@ func (g *Grant) GetCreatedAt() Timestamp { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (g *Grant) GetID() int { +func (g *Grant) GetID() int64 { if g == nil || g.ID == nil { return 0 } @@ -1773,21 +3181,13 @@ func (h *Hook) GetCreatedAt() time.Time { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (h *Hook) GetID() int { +func (h *Hook) GetID() int64 { if h == nil || h.ID == nil { return 0 } return *h.ID } -// GetName returns the Name field if it's non-nil, zero value otherwise. -func (h *Hook) GetName() string { - if h == nil || h.Name == nil { - return "" - } - return *h.Name -} - // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (h *Hook) GetUpdatedAt() time.Time { if h == nil || h.UpdatedAt == nil { @@ -1804,6 +3204,30 @@ func (h *Hook) GetURL() string { return *h.URL } +// GetActiveHooks returns the ActiveHooks field if it's non-nil, zero value otherwise. +func (h *HookStats) GetActiveHooks() int { + if h == nil || h.ActiveHooks == nil { + return 0 + } + return *h.ActiveHooks +} + +// GetInactiveHooks returns the InactiveHooks field if it's non-nil, zero value otherwise. +func (h *HookStats) GetInactiveHooks() int { + if h == nil || h.InactiveHooks == nil { + return 0 + } + return *h.InactiveHooks +} + +// GetTotalHooks returns the TotalHooks field if it's non-nil, zero value otherwise. +func (h *HookStats) GetTotalHooks() int { + if h == nil || h.TotalHooks == nil { + return 0 + } + return *h.TotalHooks +} + // GetAuthorsCount returns the AuthorsCount field if it's non-nil, zero value otherwise. func (i *Import) GetAuthorsCount() int { if i == nil || i.AuthorsCount == nil { @@ -1988,6 +3412,30 @@ func (i *Installation) GetAccessTokensURL() string { return *i.AccessTokensURL } +// GetAccount returns the Account field. +func (i *Installation) GetAccount() *User { + if i == nil { + return nil + } + return i.Account +} + +// GetAppID returns the AppID field if it's non-nil, zero value otherwise. +func (i *Installation) GetAppID() int64 { + if i == nil || i.AppID == nil { + return 0 + } + return *i.AppID +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (i *Installation) GetCreatedAt() Timestamp { + if i == nil || i.CreatedAt == nil { + return Timestamp{} + } + return *i.CreatedAt +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (i *Installation) GetHTMLURL() string { if i == nil || i.HTMLURL == nil { @@ -1997,13 +3445,21 @@ func (i *Installation) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (i *Installation) GetID() int { +func (i *Installation) GetID() int64 { if i == nil || i.ID == nil { return 0 } return *i.ID } +// GetPermissions returns the Permissions field. +func (i *Installation) GetPermissions() *InstallationPermissions { + if i == nil { + return nil + } + return i.Permissions +} + // GetRepositoriesURL returns the RepositoriesURL field if it's non-nil, zero value otherwise. func (i *Installation) GetRepositoriesURL() string { if i == nil || i.RepositoriesURL == nil { @@ -2012,6 +3468,46 @@ func (i *Installation) GetRepositoriesURL() string { return *i.RepositoriesURL } +// GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. +func (i *Installation) GetRepositorySelection() string { + if i == nil || i.RepositorySelection == nil { + return "" + } + return *i.RepositorySelection +} + +// GetSingleFileName returns the SingleFileName field if it's non-nil, zero value otherwise. +func (i *Installation) GetSingleFileName() string { + if i == nil || i.SingleFileName == nil { + return "" + } + return *i.SingleFileName +} + +// GetTargetID returns the TargetID field if it's non-nil, zero value otherwise. +func (i *Installation) GetTargetID() int64 { + if i == nil || i.TargetID == nil { + return 0 + } + return *i.TargetID +} + +// GetTargetType returns the TargetType field if it's non-nil, zero value otherwise. +func (i *Installation) GetTargetType() string { + if i == nil || i.TargetType == nil { + return "" + } + return *i.TargetType +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (i *Installation) GetUpdatedAt() Timestamp { + if i == nil || i.UpdatedAt == nil { + return Timestamp{} + } + return *i.UpdatedAt +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (i *InstallationEvent) GetAction() string { if i == nil || i.Action == nil { @@ -2020,6 +3516,54 @@ func (i *InstallationEvent) GetAction() string { return *i.Action } +// GetInstallation returns the Installation field. +func (i *InstallationEvent) GetInstallation() *Installation { + if i == nil { + return nil + } + return i.Installation +} + +// GetSender returns the Sender field. +func (i *InstallationEvent) GetSender() *User { + if i == nil { + return nil + } + return i.Sender +} + +// GetContents returns the Contents field if it's non-nil, zero value otherwise. +func (i *InstallationPermissions) GetContents() string { + if i == nil || i.Contents == nil { + return "" + } + return *i.Contents +} + +// GetIssues returns the Issues field if it's non-nil, zero value otherwise. +func (i *InstallationPermissions) GetIssues() string { + if i == nil || i.Issues == nil { + return "" + } + return *i.Issues +} + +// GetMetadata returns the Metadata field if it's non-nil, zero value otherwise. +func (i *InstallationPermissions) GetMetadata() string { + if i == nil || i.Metadata == nil { + return "" + } + return *i.Metadata +} + +// GetSingleFile returns the SingleFile field if it's non-nil, zero value otherwise. +func (i *InstallationPermissions) GetSingleFile() string { + if i == nil || i.SingleFile == nil { + return "" + } + return *i.SingleFile +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (i *InstallationRepositoriesEvent) GetAction() string { if i == nil || i.Action == nil { @@ -2028,6 +3572,14 @@ func (i *InstallationRepositoriesEvent) GetAction() string { return *i.Action } +// GetInstallation returns the Installation field. +func (i *InstallationRepositoriesEvent) GetInstallation() *Installation { + if i == nil { + return nil + } + return i.Installation +} + // GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. func (i *InstallationRepositoriesEvent) GetRepositorySelection() string { if i == nil || i.RepositorySelection == nil { @@ -2036,6 +3588,30 @@ func (i *InstallationRepositoriesEvent) GetRepositorySelection() string { return *i.RepositorySelection } +// GetSender returns the Sender field. +func (i *InstallationRepositoriesEvent) GetSender() *User { + if i == nil { + return nil + } + return i.Sender +} + +// GetExpiresAt returns the ExpiresAt field if it's non-nil, zero value otherwise. +func (i *InstallationToken) GetExpiresAt() time.Time { + if i == nil || i.ExpiresAt == nil { + return time.Time{} + } + return *i.ExpiresAt +} + +// GetToken returns the Token field if it's non-nil, zero value otherwise. +func (i *InstallationToken) GetToken() string { + if i == nil || i.Token == nil { + return "" + } + return *i.Token +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (i *Invitation) GetCreatedAt() time.Time { if i == nil || i.CreatedAt == nil { @@ -2053,13 +3629,29 @@ func (i *Invitation) GetEmail() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (i *Invitation) GetID() int { +func (i *Invitation) GetID() int64 { if i == nil || i.ID == nil { return 0 } return *i.ID } +// GetInvitationTeamURL returns the InvitationTeamURL field if it's non-nil, zero value otherwise. +func (i *Invitation) GetInvitationTeamURL() string { + if i == nil || i.InvitationTeamURL == nil { + return "" + } + return *i.InvitationTeamURL +} + +// GetInviter returns the Inviter field. +func (i *Invitation) GetInviter() *User { + if i == nil { + return nil + } + return i.Inviter +} + // GetLogin returns the Login field if it's non-nil, zero value otherwise. func (i *Invitation) GetLogin() string { if i == nil || i.Login == nil { @@ -2076,6 +3668,30 @@ func (i *Invitation) GetRole() string { return *i.Role } +// GetTeamCount returns the TeamCount field if it's non-nil, zero value otherwise. +func (i *Invitation) GetTeamCount() int { + if i == nil || i.TeamCount == nil { + return 0 + } + return *i.TeamCount +} + +// GetActiveLockReason returns the ActiveLockReason field if it's non-nil, zero value otherwise. +func (i *Issue) GetActiveLockReason() string { + if i == nil || i.ActiveLockReason == nil { + return "" + } + return *i.ActiveLockReason +} + +// GetAssignee returns the Assignee field. +func (i *Issue) GetAssignee() *User { + if i == nil { + return nil + } + return i.Assignee +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (i *Issue) GetBody() string { if i == nil || i.Body == nil { @@ -2092,6 +3708,14 @@ func (i *Issue) GetClosedAt() time.Time { return *i.ClosedAt } +// GetClosedBy returns the ClosedBy field. +func (i *Issue) GetClosedBy() *User { + if i == nil { + return nil + } + return i.ClosedBy +} + // GetComments returns the Comments field if it's non-nil, zero value otherwise. func (i *Issue) GetComments() int { if i == nil || i.Comments == nil { @@ -2133,7 +3757,7 @@ func (i *Issue) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (i *Issue) GetID() int { +func (i *Issue) GetID() int64 { if i == nil || i.ID == nil { return 0 } @@ -2156,6 +3780,22 @@ func (i *Issue) GetLocked() bool { return *i.Locked } +// GetMilestone returns the Milestone field. +func (i *Issue) GetMilestone() *Milestone { + if i == nil { + return nil + } + return i.Milestone +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (i *Issue) GetNodeID() string { + if i == nil || i.NodeID == nil { + return "" + } + return *i.NodeID +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (i *Issue) GetNumber() int { if i == nil || i.Number == nil { @@ -2164,6 +3804,30 @@ func (i *Issue) GetNumber() int { return *i.Number } +// GetPullRequestLinks returns the PullRequestLinks field. +func (i *Issue) GetPullRequestLinks() *PullRequestLinks { + if i == nil { + return nil + } + return i.PullRequestLinks +} + +// GetReactions returns the Reactions field. +func (i *Issue) GetReactions() *Reactions { + if i == nil { + return nil + } + return i.Reactions +} + +// GetRepository returns the Repository field. +func (i *Issue) GetRepository() *Repository { + if i == nil { + return nil + } + return i.Repository +} + // GetRepositoryURL returns the RepositoryURL field if it's non-nil, zero value otherwise. func (i *Issue) GetRepositoryURL() string { if i == nil || i.RepositoryURL == nil { @@ -2204,6 +3868,22 @@ func (i *Issue) GetURL() string { return *i.URL } +// GetUser returns the User field. +func (i *Issue) GetUser() *User { + if i == nil { + return nil + } + return i.User +} + +// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise. +func (i *IssueComment) GetAuthorAssociation() string { + if i == nil || i.AuthorAssociation == nil { + return "" + } + return *i.AuthorAssociation +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (i *IssueComment) GetBody() string { if i == nil || i.Body == nil { @@ -2229,7 +3909,7 @@ func (i *IssueComment) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (i *IssueComment) GetID() int { +func (i *IssueComment) GetID() int64 { if i == nil || i.ID == nil { return 0 } @@ -2244,6 +3924,22 @@ func (i *IssueComment) GetIssueURL() string { return *i.IssueURL } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (i *IssueComment) GetNodeID() string { + if i == nil || i.NodeID == nil { + return "" + } + return *i.NodeID +} + +// GetReactions returns the Reactions field. +func (i *IssueComment) GetReactions() *Reactions { + if i == nil { + return nil + } + return i.Reactions +} + // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (i *IssueComment) GetUpdatedAt() time.Time { if i == nil || i.UpdatedAt == nil { @@ -2260,6 +3956,14 @@ func (i *IssueComment) GetURL() string { return *i.URL } +// GetUser returns the User field. +func (i *IssueComment) GetUser() *User { + if i == nil { + return nil + } + return i.User +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (i *IssueCommentEvent) GetAction() string { if i == nil || i.Action == nil { @@ -2268,6 +3972,78 @@ func (i *IssueCommentEvent) GetAction() string { return *i.Action } +// GetChanges returns the Changes field. +func (i *IssueCommentEvent) GetChanges() *EditChange { + if i == nil { + return nil + } + return i.Changes +} + +// GetComment returns the Comment field. +func (i *IssueCommentEvent) GetComment() *IssueComment { + if i == nil { + return nil + } + return i.Comment +} + +// GetInstallation returns the Installation field. +func (i *IssueCommentEvent) GetInstallation() *Installation { + if i == nil { + return nil + } + return i.Installation +} + +// GetIssue returns the Issue field. +func (i *IssueCommentEvent) GetIssue() *Issue { + if i == nil { + return nil + } + return i.Issue +} + +// GetRepo returns the Repo field. +func (i *IssueCommentEvent) GetRepo() *Repository { + if i == nil { + return nil + } + return i.Repo +} + +// GetSender returns the Sender field. +func (i *IssueCommentEvent) GetSender() *User { + if i == nil { + return nil + } + return i.Sender +} + +// GetActor returns the Actor field. +func (i *IssueEvent) GetActor() *User { + if i == nil { + return nil + } + return i.Actor +} + +// GetAssignee returns the Assignee field. +func (i *IssueEvent) GetAssignee() *User { + if i == nil { + return nil + } + return i.Assignee +} + +// GetAssigner returns the Assigner field. +func (i *IssueEvent) GetAssigner() *User { + if i == nil { + return nil + } + return i.Assigner +} + // GetCommitID returns the CommitID field if it's non-nil, zero value otherwise. func (i *IssueEvent) GetCommitID() string { if i == nil || i.CommitID == nil { @@ -2293,13 +4069,61 @@ func (i *IssueEvent) GetEvent() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (i *IssueEvent) GetID() int { +func (i *IssueEvent) GetID() int64 { if i == nil || i.ID == nil { return 0 } return *i.ID } +// GetIssue returns the Issue field. +func (i *IssueEvent) GetIssue() *Issue { + if i == nil { + return nil + } + return i.Issue +} + +// GetLabel returns the Label field. +func (i *IssueEvent) GetLabel() *Label { + if i == nil { + return nil + } + return i.Label +} + +// GetLockReason returns the LockReason field if it's non-nil, zero value otherwise. +func (i *IssueEvent) GetLockReason() string { + if i == nil || i.LockReason == nil { + return "" + } + return *i.LockReason +} + +// GetMilestone returns the Milestone field. +func (i *IssueEvent) GetMilestone() *Milestone { + if i == nil { + return nil + } + return i.Milestone +} + +// GetProjectCard returns the ProjectCard field. +func (i *IssueEvent) GetProjectCard() *ProjectCard { + if i == nil { + return nil + } + return i.ProjectCard +} + +// GetRename returns the Rename field. +func (i *IssueEvent) GetRename() *Rename { + if i == nil { + return nil + } + return i.Rename +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (i *IssueEvent) GetURL() string { if i == nil || i.URL == nil { @@ -2372,6 +4196,62 @@ func (i *IssuesEvent) GetAction() string { return *i.Action } +// GetAssignee returns the Assignee field. +func (i *IssuesEvent) GetAssignee() *User { + if i == nil { + return nil + } + return i.Assignee +} + +// GetChanges returns the Changes field. +func (i *IssuesEvent) GetChanges() *EditChange { + if i == nil { + return nil + } + return i.Changes +} + +// GetInstallation returns the Installation field. +func (i *IssuesEvent) GetInstallation() *Installation { + if i == nil { + return nil + } + return i.Installation +} + +// GetIssue returns the Issue field. +func (i *IssuesEvent) GetIssue() *Issue { + if i == nil { + return nil + } + return i.Issue +} + +// GetLabel returns the Label field. +func (i *IssuesEvent) GetLabel() *Label { + if i == nil { + return nil + } + return i.Label +} + +// GetRepo returns the Repo field. +func (i *IssuesEvent) GetRepo() *Repository { + if i == nil { + return nil + } + return i.Repo +} + +// GetSender returns the Sender field. +func (i *IssuesEvent) GetSender() *User { + if i == nil { + return nil + } + return i.Sender +} + // GetIncompleteResults returns the IncompleteResults field if it's non-nil, zero value otherwise. func (i *IssuesSearchResult) GetIncompleteResults() bool { if i == nil || i.IncompleteResults == nil { @@ -2388,8 +4268,32 @@ func (i *IssuesSearchResult) GetTotal() int { return *i.Total } +// GetClosedIssues returns the ClosedIssues field if it's non-nil, zero value otherwise. +func (i *IssueStats) GetClosedIssues() int { + if i == nil || i.ClosedIssues == nil { + return 0 + } + return *i.ClosedIssues +} + +// GetOpenIssues returns the OpenIssues field if it's non-nil, zero value otherwise. +func (i *IssueStats) GetOpenIssues() int { + if i == nil || i.OpenIssues == nil { + return 0 + } + return *i.OpenIssues +} + +// GetTotalIssues returns the TotalIssues field if it's non-nil, zero value otherwise. +func (i *IssueStats) GetTotalIssues() int { + if i == nil || i.TotalIssues == nil { + return 0 + } + return *i.TotalIssues +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (k *Key) GetID() int { +func (k *Key) GetID() int64 { if k == nil || k.ID == nil { return 0 } @@ -2436,8 +4340,24 @@ func (l *Label) GetColor() string { return *l.Color } +// GetDefault returns the Default field if it's non-nil, zero value otherwise. +func (l *Label) GetDefault() bool { + if l == nil || l.Default == nil { + return false + } + return *l.Default +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (l *Label) GetDescription() string { + if l == nil || l.Description == nil { + return "" + } + return *l.Description +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (l *Label) GetID() int { +func (l *Label) GetID() int64 { if l == nil || l.ID == nil { return 0 } @@ -2452,6 +4372,14 @@ func (l *Label) GetName() string { return *l.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (l *Label) GetNodeID() string { + if l == nil || l.NodeID == nil { + return "" + } + return *l.NodeID +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (l *Label) GetURL() string { if l == nil || l.URL == nil { @@ -2468,6 +4396,118 @@ func (l *LabelEvent) GetAction() string { return *l.Action } +// GetChanges returns the Changes field. +func (l *LabelEvent) GetChanges() *EditChange { + if l == nil { + return nil + } + return l.Changes +} + +// GetInstallation returns the Installation field. +func (l *LabelEvent) GetInstallation() *Installation { + if l == nil { + return nil + } + return l.Installation +} + +// GetLabel returns the Label field. +func (l *LabelEvent) GetLabel() *Label { + if l == nil { + return nil + } + return l.Label +} + +// GetOrg returns the Org field. +func (l *LabelEvent) GetOrg() *Organization { + if l == nil { + return nil + } + return l.Org +} + +// GetRepo returns the Repo field. +func (l *LabelEvent) GetRepo() *Repository { + if l == nil { + return nil + } + return l.Repo +} + +// GetColor returns the Color field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetColor() string { + if l == nil || l.Color == nil { + return "" + } + return *l.Color +} + +// GetDefault returns the Default field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetDefault() bool { + if l == nil || l.Default == nil { + return false + } + return *l.Default +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetDescription() string { + if l == nil || l.Description == nil { + return "" + } + return *l.Description +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetID() int64 { + if l == nil || l.ID == nil { + return 0 + } + return *l.ID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetName() string { + if l == nil || l.Name == nil { + return "" + } + return *l.Name +} + +// GetScore returns the Score field. +func (l *LabelResult) GetScore() *float64 { + if l == nil { + return nil + } + return l.Score +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (l *LabelResult) GetURL() string { + if l == nil || l.URL == nil { + return "" + } + return *l.URL +} + +// GetIncompleteResults returns the IncompleteResults field if it's non-nil, zero value otherwise. +func (l *LabelsSearchResult) GetIncompleteResults() bool { + if l == nil || l.IncompleteResults == nil { + return false + } + return *l.IncompleteResults +} + +// GetTotal returns the Total field if it's non-nil, zero value otherwise. +func (l *LabelsSearchResult) GetTotal() int { + if l == nil || l.Total == nil { + return 0 + } + return *l.Total +} + // GetOID returns the OID field if it's non-nil, zero value otherwise. func (l *LargeFile) GetOID() string { if l == nil || l.OID == nil { @@ -2596,28 +4636,356 @@ func (l *License) GetURL() string { return *l.URL } -// GetContext returns the Context field if it's non-nil, zero value otherwise. -func (m *markdownRequest) GetContext() string { - if m == nil || m.Context == nil { +// GetCheckName returns the CheckName field if it's non-nil, zero value otherwise. +func (l *ListCheckRunsOptions) GetCheckName() string { + if l == nil || l.CheckName == nil { return "" } - return *m.Context + return *l.CheckName } -// GetMode returns the Mode field if it's non-nil, zero value otherwise. -func (m *markdownRequest) GetMode() string { - if m == nil || m.Mode == nil { +// GetFilter returns the Filter field if it's non-nil, zero value otherwise. +func (l *ListCheckRunsOptions) GetFilter() string { + if l == nil || l.Filter == nil { return "" } - return *m.Mode + return *l.Filter } -// GetText returns the Text field if it's non-nil, zero value otherwise. -func (m *markdownRequest) GetText() string { - if m == nil || m.Text == nil { +// GetStatus returns the Status field if it's non-nil, zero value otherwise. +func (l *ListCheckRunsOptions) GetStatus() string { + if l == nil || l.Status == nil { return "" } - return *m.Text + return *l.Status +} + +// GetTotal returns the Total field if it's non-nil, zero value otherwise. +func (l *ListCheckRunsResults) GetTotal() int { + if l == nil || l.Total == nil { + return 0 + } + return *l.Total +} + +// GetAppID returns the AppID field if it's non-nil, zero value otherwise. +func (l *ListCheckSuiteOptions) GetAppID() int { + if l == nil || l.AppID == nil { + return 0 + } + return *l.AppID +} + +// GetCheckName returns the CheckName field if it's non-nil, zero value otherwise. +func (l *ListCheckSuiteOptions) GetCheckName() string { + if l == nil || l.CheckName == nil { + return "" + } + return *l.CheckName +} + +// GetTotal returns the Total field if it's non-nil, zero value otherwise. +func (l *ListCheckSuiteResults) GetTotal() int { + if l == nil || l.Total == nil { + return 0 + } + return *l.Total +} + +// GetEffectiveDate returns the EffectiveDate field if it's non-nil, zero value otherwise. +func (m *MarketplacePendingChange) GetEffectiveDate() Timestamp { + if m == nil || m.EffectiveDate == nil { + return Timestamp{} + } + return *m.EffectiveDate +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (m *MarketplacePendingChange) GetID() int64 { + if m == nil || m.ID == nil { + return 0 + } + return *m.ID +} + +// GetPlan returns the Plan field. +func (m *MarketplacePendingChange) GetPlan() *MarketplacePlan { + if m == nil { + return nil + } + return m.Plan +} + +// GetUnitCount returns the UnitCount field if it's non-nil, zero value otherwise. +func (m *MarketplacePendingChange) GetUnitCount() int { + if m == nil || m.UnitCount == nil { + return 0 + } + return *m.UnitCount +} + +// GetAccountsURL returns the AccountsURL field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetAccountsURL() string { + if m == nil || m.AccountsURL == nil { + return "" + } + return *m.AccountsURL +} + +// GetBullets returns the Bullets field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetBullets() []string { + if m == nil || m.Bullets == nil { + return nil + } + return *m.Bullets +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetDescription() string { + if m == nil || m.Description == nil { + return "" + } + return *m.Description +} + +// GetHasFreeTrial returns the HasFreeTrial field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetHasFreeTrial() bool { + if m == nil || m.HasFreeTrial == nil { + return false + } + return *m.HasFreeTrial +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetID() int64 { + if m == nil || m.ID == nil { + return 0 + } + return *m.ID +} + +// GetMonthlyPriceInCents returns the MonthlyPriceInCents field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetMonthlyPriceInCents() int { + if m == nil || m.MonthlyPriceInCents == nil { + return 0 + } + return *m.MonthlyPriceInCents +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetName() string { + if m == nil || m.Name == nil { + return "" + } + return *m.Name +} + +// GetPriceModel returns the PriceModel field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetPriceModel() string { + if m == nil || m.PriceModel == nil { + return "" + } + return *m.PriceModel +} + +// GetState returns the State field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetState() string { + if m == nil || m.State == nil { + return "" + } + return *m.State +} + +// GetUnitName returns the UnitName field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetUnitName() string { + if m == nil || m.UnitName == nil { + return "" + } + return *m.UnitName +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetURL() string { + if m == nil || m.URL == nil { + return "" + } + return *m.URL +} + +// GetYearlyPriceInCents returns the YearlyPriceInCents field if it's non-nil, zero value otherwise. +func (m *MarketplacePlan) GetYearlyPriceInCents() int { + if m == nil || m.YearlyPriceInCents == nil { + return 0 + } + return *m.YearlyPriceInCents +} + +// GetEmail returns the Email field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetEmail() string { + if m == nil || m.Email == nil { + return "" + } + return *m.Email +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetID() int64 { + if m == nil || m.ID == nil { + return 0 + } + return *m.ID +} + +// GetLogin returns the Login field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetLogin() string { + if m == nil || m.Login == nil { + return "" + } + return *m.Login +} + +// GetMarketplacePendingChange returns the MarketplacePendingChange field. +func (m *MarketplacePlanAccount) GetMarketplacePendingChange() *MarketplacePendingChange { + if m == nil { + return nil + } + return m.MarketplacePendingChange +} + +// GetMarketplacePurchase returns the MarketplacePurchase field. +func (m *MarketplacePlanAccount) GetMarketplacePurchase() *MarketplacePurchase { + if m == nil { + return nil + } + return m.MarketplacePurchase +} + +// GetOrganizationBillingEmail returns the OrganizationBillingEmail field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetOrganizationBillingEmail() string { + if m == nil || m.OrganizationBillingEmail == nil { + return "" + } + return *m.OrganizationBillingEmail +} + +// GetType returns the Type field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetType() string { + if m == nil || m.Type == nil { + return "" + } + return *m.Type +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (m *MarketplacePlanAccount) GetURL() string { + if m == nil || m.URL == nil { + return "" + } + return *m.URL +} + +// GetAccount returns the Account field. +func (m *MarketplacePurchase) GetAccount() *MarketplacePlanAccount { + if m == nil { + return nil + } + return m.Account +} + +// GetBillingCycle returns the BillingCycle field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchase) GetBillingCycle() string { + if m == nil || m.BillingCycle == nil { + return "" + } + return *m.BillingCycle +} + +// GetFreeTrialEndsOn returns the FreeTrialEndsOn field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchase) GetFreeTrialEndsOn() Timestamp { + if m == nil || m.FreeTrialEndsOn == nil { + return Timestamp{} + } + return *m.FreeTrialEndsOn +} + +// GetNextBillingDate returns the NextBillingDate field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchase) GetNextBillingDate() Timestamp { + if m == nil || m.NextBillingDate == nil { + return Timestamp{} + } + return *m.NextBillingDate +} + +// GetOnFreeTrial returns the OnFreeTrial field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchase) GetOnFreeTrial() bool { + if m == nil || m.OnFreeTrial == nil { + return false + } + return *m.OnFreeTrial +} + +// GetPlan returns the Plan field. +func (m *MarketplacePurchase) GetPlan() *MarketplacePlan { + if m == nil { + return nil + } + return m.Plan +} + +// GetUnitCount returns the UnitCount field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchase) GetUnitCount() int { + if m == nil || m.UnitCount == nil { + return 0 + } + return *m.UnitCount +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseEvent) GetAction() string { + if m == nil || m.Action == nil { + return "" + } + return *m.Action +} + +// GetEffectiveDate returns the EffectiveDate field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseEvent) GetEffectiveDate() Timestamp { + if m == nil || m.EffectiveDate == nil { + return Timestamp{} + } + return *m.EffectiveDate +} + +// GetInstallation returns the Installation field. +func (m *MarketplacePurchaseEvent) GetInstallation() *Installation { + if m == nil { + return nil + } + return m.Installation +} + +// GetMarketplacePurchase returns the MarketplacePurchase field. +func (m *MarketplacePurchaseEvent) GetMarketplacePurchase() *MarketplacePurchase { + if m == nil { + return nil + } + return m.MarketplacePurchase +} + +// GetPreviousMarketplacePurchase returns the PreviousMarketplacePurchase field. +func (m *MarketplacePurchaseEvent) GetPreviousMarketplacePurchase() *MarketplacePurchase { + if m == nil { + return nil + } + return m.PreviousMarketplacePurchase +} + +// GetSender returns the Sender field. +func (m *MarketplacePurchaseEvent) GetSender() *User { + if m == nil { + return nil + } + return m.Sender } // GetText returns the Text field if it's non-nil, zero value otherwise. @@ -2636,6 +5004,46 @@ func (m *MemberEvent) GetAction() string { return *m.Action } +// GetInstallation returns the Installation field. +func (m *MemberEvent) GetInstallation() *Installation { + if m == nil { + return nil + } + return m.Installation +} + +// GetMember returns the Member field. +func (m *MemberEvent) GetMember() *User { + if m == nil { + return nil + } + return m.Member +} + +// GetRepo returns the Repo field. +func (m *MemberEvent) GetRepo() *Repository { + if m == nil { + return nil + } + return m.Repo +} + +// GetSender returns the Sender field. +func (m *MemberEvent) GetSender() *User { + if m == nil { + return nil + } + return m.Sender +} + +// GetOrganization returns the Organization field. +func (m *Membership) GetOrganization() *Organization { + if m == nil { + return nil + } + return m.Organization +} + // GetOrganizationURL returns the OrganizationURL field if it's non-nil, zero value otherwise. func (m *Membership) GetOrganizationURL() string { if m == nil || m.OrganizationURL == nil { @@ -2668,6 +5076,14 @@ func (m *Membership) GetURL() string { return *m.URL } +// GetUser returns the User field. +func (m *Membership) GetUser() *User { + if m == nil { + return nil + } + return m.User +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (m *MembershipEvent) GetAction() string { if m == nil || m.Action == nil { @@ -2676,6 +5092,30 @@ func (m *MembershipEvent) GetAction() string { return *m.Action } +// GetInstallation returns the Installation field. +func (m *MembershipEvent) GetInstallation() *Installation { + if m == nil { + return nil + } + return m.Installation +} + +// GetMember returns the Member field. +func (m *MembershipEvent) GetMember() *User { + if m == nil { + return nil + } + return m.Member +} + +// GetOrg returns the Org field. +func (m *MembershipEvent) GetOrg() *Organization { + if m == nil { + return nil + } + return m.Org +} + // GetScope returns the Scope field if it's non-nil, zero value otherwise. func (m *MembershipEvent) GetScope() string { if m == nil || m.Scope == nil { @@ -2684,6 +5124,22 @@ func (m *MembershipEvent) GetScope() string { return *m.Scope } +// GetSender returns the Sender field. +func (m *MembershipEvent) GetSender() *User { + if m == nil { + return nil + } + return m.Sender +} + +// GetTeam returns the Team field. +func (m *MembershipEvent) GetTeam() *Team { + if m == nil { + return nil + } + return m.Team +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (m *Metric) GetHTMLURL() string { if m == nil || m.HTMLURL == nil { @@ -2741,7 +5197,7 @@ func (m *Migration) GetGUID() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (m *Migration) GetID() int { +func (m *Migration) GetID() int64 { if m == nil || m.ID == nil { return 0 } @@ -2804,6 +5260,14 @@ func (m *Milestone) GetCreatedAt() time.Time { return *m.CreatedAt } +// GetCreator returns the Creator field. +func (m *Milestone) GetCreator() *User { + if m == nil { + return nil + } + return m.Creator +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (m *Milestone) GetDescription() string { if m == nil || m.Description == nil { @@ -2829,7 +5293,7 @@ func (m *Milestone) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (m *Milestone) GetID() int { +func (m *Milestone) GetID() int64 { if m == nil || m.ID == nil { return 0 } @@ -2844,6 +5308,14 @@ func (m *Milestone) GetLabelsURL() string { return *m.LabelsURL } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (m *Milestone) GetNodeID() string { + if m == nil || m.NodeID == nil { + return "" + } + return *m.NodeID +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (m *Milestone) GetNumber() int { if m == nil || m.Number == nil { @@ -2900,6 +5372,78 @@ func (m *MilestoneEvent) GetAction() string { return *m.Action } +// GetChanges returns the Changes field. +func (m *MilestoneEvent) GetChanges() *EditChange { + if m == nil { + return nil + } + return m.Changes +} + +// GetInstallation returns the Installation field. +func (m *MilestoneEvent) GetInstallation() *Installation { + if m == nil { + return nil + } + return m.Installation +} + +// GetMilestone returns the Milestone field. +func (m *MilestoneEvent) GetMilestone() *Milestone { + if m == nil { + return nil + } + return m.Milestone +} + +// GetOrg returns the Org field. +func (m *MilestoneEvent) GetOrg() *Organization { + if m == nil { + return nil + } + return m.Org +} + +// GetRepo returns the Repo field. +func (m *MilestoneEvent) GetRepo() *Repository { + if m == nil { + return nil + } + return m.Repo +} + +// GetSender returns the Sender field. +func (m *MilestoneEvent) GetSender() *User { + if m == nil { + return nil + } + return m.Sender +} + +// GetClosedMilestones returns the ClosedMilestones field if it's non-nil, zero value otherwise. +func (m *MilestoneStats) GetClosedMilestones() int { + if m == nil || m.ClosedMilestones == nil { + return 0 + } + return *m.ClosedMilestones +} + +// GetOpenMilestones returns the OpenMilestones field if it's non-nil, zero value otherwise. +func (m *MilestoneStats) GetOpenMilestones() int { + if m == nil || m.OpenMilestones == nil { + return 0 + } + return *m.OpenMilestones +} + +// GetTotalMilestones returns the TotalMilestones field if it's non-nil, zero value otherwise. +func (m *MilestoneStats) GetTotalMilestones() int { + if m == nil || m.TotalMilestones == nil { + return 0 + } + return *m.TotalMilestones +} + // GetBase returns the Base field if it's non-nil, zero value otherwise. func (n *NewPullRequest) GetBase() string { if n == nil || n.Base == nil { @@ -2948,6 +5492,46 @@ func (n *NewPullRequest) GetTitle() string { return *n.Title } +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetDescription() string { + if n == nil || n.Description == nil { + return "" + } + return *n.Description +} + +// GetLDAPDN returns the LDAPDN field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetLDAPDN() string { + if n == nil || n.LDAPDN == nil { + return "" + } + return *n.LDAPDN +} + +// GetParentTeamID returns the ParentTeamID field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetParentTeamID() int64 { + if n == nil || n.ParentTeamID == nil { + return 0 + } + return *n.ParentTeamID +} + +// GetPermission returns the Permission field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetPermission() string { + if n == nil || n.Permission == nil { + return "" + } + return *n.Permission +} + +// GetPrivacy returns the Privacy field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetPrivacy() string { + if n == nil || n.Privacy == nil { + return "" + } + return *n.Privacy +} + // GetID returns the ID field if it's non-nil, zero value otherwise. func (n *Notification) GetID() string { if n == nil || n.ID == nil { @@ -2972,6 +5556,22 @@ func (n *Notification) GetReason() string { return *n.Reason } +// GetRepository returns the Repository field. +func (n *Notification) GetRepository() *Repository { + if n == nil { + return nil + } + return n.Repository +} + +// GetSubject returns the Subject field. +func (n *Notification) GetSubject() *NotificationSubject { + if n == nil { + return nil + } + return n.Subject +} + // GetUnread returns the Unread field if it's non-nil, zero value otherwise. func (n *Notification) GetUnread() bool { if n == nil || n.Unread == nil { @@ -3076,6 +5676,22 @@ func (o *Organization) GetCreatedAt() time.Time { return *o.CreatedAt } +// GetDefaultRepoPermission returns the DefaultRepoPermission field if it's non-nil, zero value otherwise. +func (o *Organization) GetDefaultRepoPermission() string { + if o == nil || o.DefaultRepoPermission == nil { + return "" + } + return *o.DefaultRepoPermission +} + +// GetDefaultRepoSettings returns the DefaultRepoSettings field if it's non-nil, zero value otherwise. +func (o *Organization) GetDefaultRepoSettings() string { + if o == nil || o.DefaultRepoSettings == nil { + return "" + } + return *o.DefaultRepoSettings +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (o *Organization) GetDescription() string { if o == nil || o.Description == nil { @@ -3141,7 +5757,7 @@ func (o *Organization) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (o *Organization) GetID() int { +func (o *Organization) GetID() int64 { if o == nil || o.ID == nil { return 0 } @@ -3172,6 +5788,14 @@ func (o *Organization) GetLogin() string { return *o.Login } +// GetMembersCanCreateRepos returns the MembersCanCreateRepos field if it's non-nil, zero value otherwise. +func (o *Organization) GetMembersCanCreateRepos() bool { + if o == nil || o.MembersCanCreateRepos == nil { + return false + } + return *o.MembersCanCreateRepos +} + // GetMembersURL returns the MembersURL field if it's non-nil, zero value otherwise. func (o *Organization) GetMembersURL() string { if o == nil || o.MembersURL == nil { @@ -3188,6 +5812,14 @@ func (o *Organization) GetName() string { return *o.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (o *Organization) GetNodeID() string { + if o == nil || o.NodeID == nil { + return "" + } + return *o.NodeID +} + // GetOwnedPrivateRepos returns the OwnedPrivateRepos field if it's non-nil, zero value otherwise. func (o *Organization) GetOwnedPrivateRepos() int { if o == nil || o.OwnedPrivateRepos == nil { @@ -3196,6 +5828,14 @@ func (o *Organization) GetOwnedPrivateRepos() int { return *o.OwnedPrivateRepos } +// GetPlan returns the Plan field. +func (o *Organization) GetPlan() *Plan { + if o == nil { + return nil + } + return o.Plan +} + // GetPrivateGists returns the PrivateGists field if it's non-nil, zero value otherwise. func (o *Organization) GetPrivateGists() int { if o == nil || o.PrivateGists == nil { @@ -3244,6 +5884,14 @@ func (o *Organization) GetTotalPrivateRepos() int { return *o.TotalPrivateRepos } +// GetTwoFactorRequirementEnabled returns the TwoFactorRequirementEnabled field if it's non-nil, zero value otherwise. +func (o *Organization) GetTwoFactorRequirementEnabled() bool { + if o == nil || o.TwoFactorRequirementEnabled == nil { + return false + } + return *o.TwoFactorRequirementEnabled +} + // GetType returns the Type field if it's non-nil, zero value otherwise. func (o *Organization) GetType() string { if o == nil || o.Type == nil { @@ -3276,6 +5924,46 @@ func (o *OrganizationEvent) GetAction() string { return *o.Action } +// GetInstallation returns the Installation field. +func (o *OrganizationEvent) GetInstallation() *Installation { + if o == nil { + return nil + } + return o.Installation +} + +// GetInvitation returns the Invitation field. +func (o *OrganizationEvent) GetInvitation() *Invitation { + if o == nil { + return nil + } + return o.Invitation +} + +// GetMembership returns the Membership field. +func (o *OrganizationEvent) GetMembership() *Membership { + if o == nil { + return nil + } + return o.Membership +} + +// GetOrganization returns the Organization field. +func (o *OrganizationEvent) GetOrganization() *Organization { + if o == nil { + return nil + } + return o.Organization +} + +// GetSender returns the Sender field. +func (o *OrganizationEvent) GetSender() *User { + if o == nil { + return nil + } + return o.Sender +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (o *OrgBlockEvent) GetAction() string { if o == nil || o.Action == nil { @@ -3284,6 +5972,70 @@ func (o *OrgBlockEvent) GetAction() string { return *o.Action } +// GetBlockedUser returns the BlockedUser field. +func (o *OrgBlockEvent) GetBlockedUser() *User { + if o == nil { + return nil + } + return o.BlockedUser +} + +// GetInstallation returns the Installation field. +func (o *OrgBlockEvent) GetInstallation() *Installation { + if o == nil { + return nil + } + return o.Installation +} + +// GetOrganization returns the Organization field. +func (o *OrgBlockEvent) GetOrganization() *Organization { + if o == nil { + return nil + } + return o.Organization +} + +// GetSender returns the Sender field. +func (o *OrgBlockEvent) GetSender() *User { + if o == nil { + return nil + } + return o.Sender +} + +// GetDisabledOrgs returns the DisabledOrgs field if it's non-nil, zero value otherwise. +func (o *OrgStats) GetDisabledOrgs() int { + if o == nil || o.DisabledOrgs == nil { + return 0 + } + return *o.DisabledOrgs +} + +// GetTotalOrgs returns the TotalOrgs field if it's non-nil, zero value otherwise. +func (o *OrgStats) GetTotalOrgs() int { + if o == nil || o.TotalOrgs == nil { + return 0 + } + return *o.TotalOrgs +} + +// GetTotalTeamMembers returns the TotalTeamMembers field if it's non-nil, zero value otherwise. +func (o *OrgStats) GetTotalTeamMembers() int { + if o == nil || o.TotalTeamMembers == nil { + return 0 + } + return *o.TotalTeamMembers +} + +// GetTotalTeams returns the TotalTeams field if it's non-nil, zero value otherwise. +func (o *OrgStats) GetTotalTeams() int { + if o == nil || o.TotalTeams == nil { + return 0 + } + return *o.TotalTeams +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *Page) GetAction() string { if p == nil || p.Action == nil { @@ -3332,14 +6084,46 @@ func (p *Page) GetTitle() string { return *p.Title } +// GetBuild returns the Build field. +func (p *PageBuildEvent) GetBuild() *PagesBuild { + if p == nil { + return nil + } + return p.Build +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *PageBuildEvent) GetID() int { +func (p *PageBuildEvent) GetID() int64 { if p == nil || p.ID == nil { return 0 } return *p.ID } +// GetInstallation returns the Installation field. +func (p *PageBuildEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetRepo returns the Repo field. +func (p *PageBuildEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *PageBuildEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetCNAME returns the CNAME field if it's non-nil, zero value otherwise. func (p *Pages) GetCNAME() string { if p == nil || p.CNAME == nil { @@ -3404,6 +6188,22 @@ func (p *PagesBuild) GetDuration() int { return *p.Duration } +// GetError returns the Error field. +func (p *PagesBuild) GetError() *PagesError { + if p == nil { + return nil + } + return p.Error +} + +// GetPusher returns the Pusher field. +func (p *PagesBuild) GetPusher() *User { + if p == nil { + return nil + } + return p.Pusher +} + // GetStatus returns the Status field if it's non-nil, zero value otherwise. func (p *PagesBuild) GetStatus() string { if p == nil || p.Status == nil { @@ -3436,14 +6236,38 @@ func (p *PagesError) GetMessage() string { return *p.Message } +// GetTotalPages returns the TotalPages field if it's non-nil, zero value otherwise. +func (p *PageStats) GetTotalPages() int { + if p == nil || p.TotalPages == nil { + return 0 + } + return *p.TotalPages +} + +// GetHook returns the Hook field. +func (p *PingEvent) GetHook() *Hook { + if p == nil { + return nil + } + return p.Hook +} + // GetHookID returns the HookID field if it's non-nil, zero value otherwise. -func (p *PingEvent) GetHookID() int { +func (p *PingEvent) GetHookID() int64 { if p == nil || p.HookID == nil { return 0 } return *p.HookID } +// GetInstallation returns the Installation field. +func (p *PingEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + // GetZen returns the Zen field if it's non-nil, zero value otherwise. func (p *PingEvent) GetZen() string { if p == nil || p.Zen == nil { @@ -3484,6 +6308,110 @@ func (p *Plan) GetSpace() int { return *p.Space } +// GetConfigURL returns the ConfigURL field if it's non-nil, zero value otherwise. +func (p *PreReceiveHook) GetConfigURL() string { + if p == nil || p.ConfigURL == nil { + return "" + } + return *p.ConfigURL +} + +// GetEnforcement returns the Enforcement field if it's non-nil, zero value otherwise. +func (p *PreReceiveHook) GetEnforcement() string { + if p == nil || p.Enforcement == nil { + return "" + } + return *p.Enforcement +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (p *PreReceiveHook) GetID() int64 { + if p == nil || p.ID == nil { + return 0 + } + return *p.ID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (p *PreReceiveHook) GetName() string { + if p == nil || p.Name == nil { + return "" + } + return *p.Name +} + +// GetHRef returns the HRef field if it's non-nil, zero value otherwise. +func (p *PRLink) GetHRef() string { + if p == nil || p.HRef == nil { + return "" + } + return *p.HRef +} + +// GetComments returns the Comments field. +func (p *PRLinks) GetComments() *PRLink { + if p == nil { + return nil + } + return p.Comments +} + +// GetCommits returns the Commits field. +func (p *PRLinks) GetCommits() *PRLink { + if p == nil { + return nil + } + return p.Commits +} + +// GetHTML returns the HTML field. +func (p *PRLinks) GetHTML() *PRLink { + if p == nil { + return nil + } + return p.HTML +} + +// GetIssue returns the Issue field. +func (p *PRLinks) GetIssue() *PRLink { + if p == nil { + return nil + } + return p.Issue +} + +// GetReviewComment returns the ReviewComment field. +func (p *PRLinks) GetReviewComment() *PRLink { + if p == nil { + return nil + } + return p.ReviewComment +} + +// GetReviewComments returns the ReviewComments field. +func (p *PRLinks) GetReviewComments() *PRLink { + if p == nil { + return nil + } + return p.ReviewComments +} + +// GetSelf returns the Self field. +func (p *PRLinks) GetSelf() *PRLink { + if p == nil { + return nil + } + return p.Self +} + +// GetStatuses returns the Statuses field. +func (p *PRLinks) GetStatuses() *PRLink { + if p == nil { + return nil + } + return p.Statuses +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (p *Project) GetBody() string { if p == nil || p.Body == nil { @@ -3492,6 +6420,14 @@ func (p *Project) GetBody() string { return *p.Body } +// GetColumnsURL returns the ColumnsURL field if it's non-nil, zero value otherwise. +func (p *Project) GetColumnsURL() string { + if p == nil || p.ColumnsURL == nil { + return "" + } + return *p.ColumnsURL +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (p *Project) GetCreatedAt() Timestamp { if p == nil || p.CreatedAt == nil { @@ -3500,8 +6436,24 @@ func (p *Project) GetCreatedAt() Timestamp { return *p.CreatedAt } +// GetCreator returns the Creator field. +func (p *Project) GetCreator() *User { + if p == nil { + return nil + } + return p.Creator +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (p *Project) GetHTMLURL() string { + if p == nil || p.HTMLURL == nil { + return "" + } + return *p.HTMLURL +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *Project) GetID() int { +func (p *Project) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -3516,6 +6468,14 @@ func (p *Project) GetName() string { return *p.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *Project) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (p *Project) GetNumber() int { if p == nil || p.Number == nil { @@ -3532,6 +6492,14 @@ func (p *Project) GetOwnerURL() string { return *p.OwnerURL } +// GetState returns the State field if it's non-nil, zero value otherwise. +func (p *Project) GetState() string { + if p == nil || p.State == nil { + return "" + } + return *p.State +} + // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (p *Project) GetUpdatedAt() Timestamp { if p == nil || p.UpdatedAt == nil { @@ -3548,8 +6516,16 @@ func (p *Project) GetURL() string { return *p.URL } +// GetArchived returns the Archived field if it's non-nil, zero value otherwise. +func (p *ProjectCard) GetArchived() bool { + if p == nil || p.Archived == nil { + return false + } + return *p.Archived +} + // GetColumnID returns the ColumnID field if it's non-nil, zero value otherwise. -func (p *ProjectCard) GetColumnID() int { +func (p *ProjectCard) GetColumnID() int64 { if p == nil || p.ColumnID == nil { return 0 } @@ -3580,14 +6556,30 @@ func (p *ProjectCard) GetCreatedAt() Timestamp { return *p.CreatedAt } +// GetCreator returns the Creator field. +func (p *ProjectCard) GetCreator() *User { + if p == nil { + return nil + } + return p.Creator +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *ProjectCard) GetID() int { +func (p *ProjectCard) GetID() int64 { if p == nil || p.ID == nil { return 0 } return *p.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *ProjectCard) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetNote returns the Note field if it's non-nil, zero value otherwise. func (p *ProjectCard) GetNote() string { if p == nil || p.Note == nil { @@ -3621,13 +6613,85 @@ func (p *ProjectCardEvent) GetAction() string { } // GetAfterID returns the AfterID field if it's non-nil, zero value otherwise. -func (p *ProjectCardEvent) GetAfterID() int { +func (p *ProjectCardEvent) GetAfterID() int64 { if p == nil || p.AfterID == nil { return 0 } return *p.AfterID } +// GetChanges returns the Changes field. +func (p *ProjectCardEvent) GetChanges() *ProjectCardChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetInstallation returns the Installation field. +func (p *ProjectCardEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrg returns the Org field. +func (p *ProjectCardEvent) GetOrg() *Organization { + if p == nil { + return nil + } + return p.Org +} + +// GetProjectCard returns the ProjectCard field. +func (p *ProjectCardEvent) GetProjectCard() *ProjectCard { + if p == nil { + return nil + } + return p.ProjectCard +} + +// GetRepo returns the Repo field. +func (p *ProjectCardEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *ProjectCardEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + +// GetArchivedState returns the ArchivedState field if it's non-nil, zero value otherwise. +func (p *ProjectCardListOptions) GetArchivedState() string { + if p == nil || p.ArchivedState == nil { + return "" + } + return *p.ArchivedState +} + +// GetArchived returns the Archived field if it's non-nil, zero value otherwise. +func (p *ProjectCardOptions) GetArchived() bool { + if p == nil || p.Archived == nil { + return false + } + return *p.Archived +} + +// GetCardsURL returns the CardsURL field if it's non-nil, zero value otherwise. +func (p *ProjectColumn) GetCardsURL() string { + if p == nil || p.CardsURL == nil { + return "" + } + return *p.CardsURL +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (p *ProjectColumn) GetCreatedAt() Timestamp { if p == nil || p.CreatedAt == nil { @@ -3637,7 +6701,7 @@ func (p *ProjectColumn) GetCreatedAt() Timestamp { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *ProjectColumn) GetID() int { +func (p *ProjectColumn) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -3652,6 +6716,14 @@ func (p *ProjectColumn) GetName() string { return *p.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *ProjectColumn) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetProjectURL returns the ProjectURL field if it's non-nil, zero value otherwise. func (p *ProjectColumn) GetProjectURL() string { if p == nil || p.ProjectURL == nil { @@ -3668,6 +6740,14 @@ func (p *ProjectColumn) GetUpdatedAt() Timestamp { return *p.UpdatedAt } +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (p *ProjectColumn) GetURL() string { + if p == nil || p.URL == nil { + return "" + } + return *p.URL +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *ProjectColumnEvent) GetAction() string { if p == nil || p.Action == nil { @@ -3677,13 +6757,61 @@ func (p *ProjectColumnEvent) GetAction() string { } // GetAfterID returns the AfterID field if it's non-nil, zero value otherwise. -func (p *ProjectColumnEvent) GetAfterID() int { +func (p *ProjectColumnEvent) GetAfterID() int64 { if p == nil || p.AfterID == nil { return 0 } return *p.AfterID } +// GetChanges returns the Changes field. +func (p *ProjectColumnEvent) GetChanges() *ProjectColumnChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetInstallation returns the Installation field. +func (p *ProjectColumnEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrg returns the Org field. +func (p *ProjectColumnEvent) GetOrg() *Organization { + if p == nil { + return nil + } + return p.Org +} + +// GetProjectColumn returns the ProjectColumn field. +func (p *ProjectColumnEvent) GetProjectColumn() *ProjectColumn { + if p == nil { + return nil + } + return p.ProjectColumn +} + +// GetRepo returns the Repo field. +func (p *ProjectColumnEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *ProjectColumnEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *ProjectEvent) GetAction() string { if p == nil || p.Action == nil { @@ -3692,6 +6820,182 @@ func (p *ProjectEvent) GetAction() string { return *p.Action } +// GetChanges returns the Changes field. +func (p *ProjectEvent) GetChanges() *ProjectChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetInstallation returns the Installation field. +func (p *ProjectEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrg returns the Org field. +func (p *ProjectEvent) GetOrg() *Organization { + if p == nil { + return nil + } + return p.Org +} + +// GetProject returns the Project field. +func (p *ProjectEvent) GetProject() *Project { + if p == nil { + return nil + } + return p.Project +} + +// GetRepo returns the Repo field. +func (p *ProjectEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *ProjectEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetBody() string { + if p == nil || p.Body == nil { + return "" + } + return *p.Body +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetName() string { + if p == nil || p.Name == nil { + return "" + } + return *p.Name +} + +// GetOrganizationPermission returns the OrganizationPermission field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetOrganizationPermission() string { + if p == nil || p.OrganizationPermission == nil { + return "" + } + return *p.OrganizationPermission +} + +// GetPublic returns the Public field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetPublic() bool { + if p == nil || p.Public == nil { + return false + } + return *p.Public +} + +// GetState returns the State field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetState() string { + if p == nil || p.State == nil { + return "" + } + return *p.State +} + +// GetEnforceAdmins returns the EnforceAdmins field. +func (p *Protection) GetEnforceAdmins() *AdminEnforcement { + if p == nil { + return nil + } + return p.EnforceAdmins +} + +// GetRequiredPullRequestReviews returns the RequiredPullRequestReviews field. +func (p *Protection) GetRequiredPullRequestReviews() *PullRequestReviewsEnforcement { + if p == nil { + return nil + } + return p.RequiredPullRequestReviews +} + +// GetRequiredStatusChecks returns the RequiredStatusChecks field. +func (p *Protection) GetRequiredStatusChecks() *RequiredStatusChecks { + if p == nil { + return nil + } + return p.RequiredStatusChecks +} + +// GetRestrictions returns the Restrictions field. +func (p *Protection) GetRestrictions() *BranchRestrictions { + if p == nil { + return nil + } + return p.Restrictions +} + +// GetRequiredPullRequestReviews returns the RequiredPullRequestReviews field. +func (p *ProtectionRequest) GetRequiredPullRequestReviews() *PullRequestReviewsEnforcementRequest { + if p == nil { + return nil + } + return p.RequiredPullRequestReviews +} + +// GetRequiredStatusChecks returns the RequiredStatusChecks field. +func (p *ProtectionRequest) GetRequiredStatusChecks() *RequiredStatusChecks { + if p == nil { + return nil + } + return p.RequiredStatusChecks +} + +// GetRestrictions returns the Restrictions field. +func (p *ProtectionRequest) GetRestrictions() *BranchRestrictionsRequest { + if p == nil { + return nil + } + return p.Restrictions +} + +// GetInstallation returns the Installation field. +func (p *PublicEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetRepo returns the Repo field. +func (p *PublicEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *PublicEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + +// GetActiveLockReason returns the ActiveLockReason field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetActiveLockReason() string { + if p == nil || p.ActiveLockReason == nil { + return "" + } + return *p.ActiveLockReason +} + // GetAdditions returns the Additions field if it's non-nil, zero value otherwise. func (p *PullRequest) GetAdditions() int { if p == nil || p.Additions == nil { @@ -3700,6 +7004,30 @@ func (p *PullRequest) GetAdditions() int { return *p.Additions } +// GetAssignee returns the Assignee field. +func (p *PullRequest) GetAssignee() *User { + if p == nil { + return nil + } + return p.Assignee +} + +// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetAuthorAssociation() string { + if p == nil || p.AuthorAssociation == nil { + return "" + } + return *p.AuthorAssociation +} + +// GetBase returns the Base field. +func (p *PullRequest) GetBase() *PullRequestBranch { + if p == nil { + return nil + } + return p.Base +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (p *PullRequest) GetBody() string { if p == nil || p.Body == nil { @@ -3732,6 +7060,14 @@ func (p *PullRequest) GetComments() int { return *p.Comments } +// GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetCommentsURL() string { + if p == nil || p.CommentsURL == nil { + return "" + } + return *p.CommentsURL +} + // GetCommits returns the Commits field if it's non-nil, zero value otherwise. func (p *PullRequest) GetCommits() int { if p == nil || p.Commits == nil { @@ -3740,6 +7076,14 @@ func (p *PullRequest) GetCommits() int { return *p.Commits } +// GetCommitsURL returns the CommitsURL field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetCommitsURL() string { + if p == nil || p.CommitsURL == nil { + return "" + } + return *p.CommitsURL +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (p *PullRequest) GetCreatedAt() time.Time { if p == nil || p.CreatedAt == nil { @@ -3764,6 +7108,14 @@ func (p *PullRequest) GetDiffURL() string { return *p.DiffURL } +// GetHead returns the Head field. +func (p *PullRequest) GetHead() *PullRequestBranch { + if p == nil { + return nil + } + return p.Head +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (p *PullRequest) GetHTMLURL() string { if p == nil || p.HTMLURL == nil { @@ -3773,7 +7125,7 @@ func (p *PullRequest) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *PullRequest) GetID() int { +func (p *PullRequest) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -3788,6 +7140,14 @@ func (p *PullRequest) GetIssueURL() string { return *p.IssueURL } +// GetLinks returns the Links field. +func (p *PullRequest) GetLinks() *PRLinks { + if p == nil { + return nil + } + return p.Links +} + // GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise. func (p *PullRequest) GetMaintainerCanModify() bool { if p == nil || p.MaintainerCanModify == nil { @@ -3804,6 +7164,14 @@ func (p *PullRequest) GetMergeable() bool { return *p.Mergeable } +// GetMergeableState returns the MergeableState field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetMergeableState() string { + if p == nil || p.MergeableState == nil { + return "" + } + return *p.MergeableState +} + // GetMergeCommitSHA returns the MergeCommitSHA field if it's non-nil, zero value otherwise. func (p *PullRequest) GetMergeCommitSHA() string { if p == nil || p.MergeCommitSHA == nil { @@ -3828,6 +7196,30 @@ func (p *PullRequest) GetMergedAt() time.Time { return *p.MergedAt } +// GetMergedBy returns the MergedBy field. +func (p *PullRequest) GetMergedBy() *User { + if p == nil { + return nil + } + return p.MergedBy +} + +// GetMilestone returns the Milestone field. +func (p *PullRequest) GetMilestone() *Milestone { + if p == nil { + return nil + } + return p.Milestone +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (p *PullRequest) GetNumber() int { if p == nil || p.Number == nil { @@ -3900,6 +7292,14 @@ func (p *PullRequest) GetURL() string { return *p.URL } +// GetUser returns the User field. +func (p *PullRequest) GetUser() *User { + if p == nil { + return nil + } + return p.User +} + // GetLabel returns the Label field if it's non-nil, zero value otherwise. func (p *PullRequestBranch) GetLabel() string { if p == nil || p.Label == nil { @@ -3916,6 +7316,14 @@ func (p *PullRequestBranch) GetRef() string { return *p.Ref } +// GetRepo returns the Repo field. +func (p *PullRequestBranch) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (p *PullRequestBranch) GetSHA() string { if p == nil || p.SHA == nil { @@ -3924,6 +7332,22 @@ func (p *PullRequestBranch) GetSHA() string { return *p.SHA } +// GetUser returns the User field. +func (p *PullRequestBranch) GetUser() *User { + if p == nil { + return nil + } + return p.User +} + +// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise. +func (p *PullRequestComment) GetAuthorAssociation() string { + if p == nil || p.AuthorAssociation == nil { + return "" + } + return *p.AuthorAssociation +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (p *PullRequestComment) GetBody() string { if p == nil || p.Body == nil { @@ -3965,7 +7389,7 @@ func (p *PullRequestComment) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *PullRequestComment) GetID() int { +func (p *PullRequestComment) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -3973,7 +7397,7 @@ func (p *PullRequestComment) GetID() int { } // GetInReplyTo returns the InReplyTo field if it's non-nil, zero value otherwise. -func (p *PullRequestComment) GetInReplyTo() int { +func (p *PullRequestComment) GetInReplyTo() int64 { if p == nil || p.InReplyTo == nil { return 0 } @@ -4012,6 +7436,14 @@ func (p *PullRequestComment) GetPosition() int { return *p.Position } +// GetPullRequestReviewID returns the PullRequestReviewID field if it's non-nil, zero value otherwise. +func (p *PullRequestComment) GetPullRequestReviewID() int64 { + if p == nil || p.PullRequestReviewID == nil { + return 0 + } + return *p.PullRequestReviewID +} + // GetPullRequestURL returns the PullRequestURL field if it's non-nil, zero value otherwise. func (p *PullRequestComment) GetPullRequestURL() string { if p == nil || p.PullRequestURL == nil { @@ -4020,6 +7452,14 @@ func (p *PullRequestComment) GetPullRequestURL() string { return *p.PullRequestURL } +// GetReactions returns the Reactions field. +func (p *PullRequestComment) GetReactions() *Reactions { + if p == nil { + return nil + } + return p.Reactions +} + // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (p *PullRequestComment) GetUpdatedAt() time.Time { if p == nil || p.UpdatedAt == nil { @@ -4036,6 +7476,14 @@ func (p *PullRequestComment) GetURL() string { return *p.URL } +// GetUser returns the User field. +func (p *PullRequestComment) GetUser() *User { + if p == nil { + return nil + } + return p.User +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *PullRequestEvent) GetAction() string { if p == nil || p.Action == nil { @@ -4044,6 +7492,38 @@ func (p *PullRequestEvent) GetAction() string { return *p.Action } +// GetAssignee returns the Assignee field. +func (p *PullRequestEvent) GetAssignee() *User { + if p == nil { + return nil + } + return p.Assignee +} + +// GetChanges returns the Changes field. +func (p *PullRequestEvent) GetChanges() *EditChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetInstallation returns the Installation field. +func (p *PullRequestEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetLabel returns the Label field. +func (p *PullRequestEvent) GetLabel() *Label { + if p == nil { + return nil + } + return p.Label +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (p *PullRequestEvent) GetNumber() int { if p == nil || p.Number == nil { @@ -4052,6 +7532,46 @@ func (p *PullRequestEvent) GetNumber() int { return *p.Number } +// GetOrganization returns the Organization field. +func (p *PullRequestEvent) GetOrganization() *Organization { + if p == nil { + return nil + } + return p.Organization +} + +// GetPullRequest returns the PullRequest field. +func (p *PullRequestEvent) GetPullRequest() *PullRequest { + if p == nil { + return nil + } + return p.PullRequest +} + +// GetRepo returns the Repo field. +func (p *PullRequestEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetRequestedReviewer returns the RequestedReviewer field. +func (p *PullRequestEvent) GetRequestedReviewer() *User { + if p == nil { + return nil + } + return p.RequestedReviewer +} + +// GetSender returns the Sender field. +func (p *PullRequestEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetDiffURL returns the DiffURL field if it's non-nil, zero value otherwise. func (p *PullRequestLinks) GetDiffURL() string { if p == nil || p.DiffURL == nil { @@ -4133,7 +7653,7 @@ func (p *PullRequestReview) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *PullRequestReview) GetID() int { +func (p *PullRequestReview) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -4164,6 +7684,14 @@ func (p *PullRequestReview) GetSubmittedAt() time.Time { return *p.SubmittedAt } +// GetUser returns the User field. +func (p *PullRequestReview) GetUser() *User { + if p == nil { + return nil + } + return p.User +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *PullRequestReviewCommentEvent) GetAction() string { if p == nil || p.Action == nil { @@ -4172,6 +7700,54 @@ func (p *PullRequestReviewCommentEvent) GetAction() string { return *p.Action } +// GetChanges returns the Changes field. +func (p *PullRequestReviewCommentEvent) GetChanges() *EditChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetComment returns the Comment field. +func (p *PullRequestReviewCommentEvent) GetComment() *PullRequestComment { + if p == nil { + return nil + } + return p.Comment +} + +// GetInstallation returns the Installation field. +func (p *PullRequestReviewCommentEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetPullRequest returns the PullRequest field. +func (p *PullRequestReviewCommentEvent) GetPullRequest() *PullRequest { + if p == nil { + return nil + } + return p.PullRequest +} + +// GetRepo returns the Repo field. +func (p *PullRequestReviewCommentEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *PullRequestReviewCommentEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetMessage returns the Message field if it's non-nil, zero value otherwise. func (p *PullRequestReviewDismissalRequest) GetMessage() string { if p == nil || p.Message == nil { @@ -4188,6 +7764,54 @@ func (p *PullRequestReviewEvent) GetAction() string { return *p.Action } +// GetInstallation returns the Installation field. +func (p *PullRequestReviewEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrganization returns the Organization field. +func (p *PullRequestReviewEvent) GetOrganization() *Organization { + if p == nil { + return nil + } + return p.Organization +} + +// GetPullRequest returns the PullRequest field. +func (p *PullRequestReviewEvent) GetPullRequest() *PullRequest { + if p == nil { + return nil + } + return p.PullRequest +} + +// GetRepo returns the Repo field. +func (p *PullRequestReviewEvent) GetRepo() *Repository { + if p == nil { + return nil + } + return p.Repo +} + +// GetReview returns the Review field. +func (p *PullRequestReviewEvent) GetReview() *PullRequestReview { + if p == nil { + return nil + } + return p.Review +} + +// GetSender returns the Sender field. +func (p *PullRequestReviewEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (p *PullRequestReviewRequest) GetBody() string { if p == nil || p.Body == nil { @@ -4212,6 +7836,22 @@ func (p *PullRequestReviewRequest) GetEvent() string { return *p.Event } +// GetDismissalRestrictionsRequest returns the DismissalRestrictionsRequest field. +func (p *PullRequestReviewsEnforcementRequest) GetDismissalRestrictionsRequest() *DismissalRestrictionsRequest { + if p == nil { + return nil + } + return p.DismissalRestrictionsRequest +} + +// GetDismissalRestrictionsRequest returns the DismissalRestrictionsRequest field. +func (p *PullRequestReviewsEnforcementUpdate) GetDismissalRestrictionsRequest() *DismissalRestrictionsRequest { + if p == nil { + return nil + } + return p.DismissalRestrictionsRequest +} + // GetDismissStaleReviews returns the DismissStaleReviews field if it's non-nil, zero value otherwise. func (p *PullRequestReviewsEnforcementUpdate) GetDismissStaleReviews() bool { if p == nil || p.DismissStaleReviews == nil { @@ -4220,44 +7860,36 @@ func (p *PullRequestReviewsEnforcementUpdate) GetDismissStaleReviews() bool { return *p.DismissStaleReviews } -// GetBase returns the Base field if it's non-nil, zero value otherwise. -func (p *pullRequestUpdate) GetBase() string { - if p == nil || p.Base == nil { - return "" +// GetMergablePulls returns the MergablePulls field if it's non-nil, zero value otherwise. +func (p *PullStats) GetMergablePulls() int { + if p == nil || p.MergablePulls == nil { + return 0 } - return *p.Base + return *p.MergablePulls } -// GetBody returns the Body field if it's non-nil, zero value otherwise. -func (p *pullRequestUpdate) GetBody() string { - if p == nil || p.Body == nil { - return "" +// GetMergedPulls returns the MergedPulls field if it's non-nil, zero value otherwise. +func (p *PullStats) GetMergedPulls() int { + if p == nil || p.MergedPulls == nil { + return 0 } - return *p.Body + return *p.MergedPulls } -// GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise. -func (p *pullRequestUpdate) GetMaintainerCanModify() bool { - if p == nil || p.MaintainerCanModify == nil { - return false +// GetTotalPulls returns the TotalPulls field if it's non-nil, zero value otherwise. +func (p *PullStats) GetTotalPulls() int { + if p == nil || p.TotalPulls == nil { + return 0 } - return *p.MaintainerCanModify + return *p.TotalPulls } -// GetState returns the State field if it's non-nil, zero value otherwise. -func (p *pullRequestUpdate) GetState() string { - if p == nil || p.State == nil { - return "" +// GetUnmergablePulls returns the UnmergablePulls field if it's non-nil, zero value otherwise. +func (p *PullStats) GetUnmergablePulls() int { + if p == nil || p.UnmergablePulls == nil { + return 0 } - return *p.State -} - -// GetTitle returns the Title field if it's non-nil, zero value otherwise. -func (p *pullRequestUpdate) GetTitle() string { - if p == nil || p.Title == nil { - return "" - } - return *p.Title + return *p.UnmergablePulls } // GetCommits returns the Commits field if it's non-nil, zero value otherwise. @@ -4356,8 +7988,32 @@ func (p *PushEvent) GetHead() string { return *p.Head } +// GetHeadCommit returns the HeadCommit field. +func (p *PushEvent) GetHeadCommit() *PushEventCommit { + if p == nil { + return nil + } + return p.HeadCommit +} + +// GetInstallation returns the Installation field. +func (p *PushEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetPusher returns the Pusher field. +func (p *PushEvent) GetPusher() *User { + if p == nil { + return nil + } + return p.Pusher +} + // GetPushID returns the PushID field if it's non-nil, zero value otherwise. -func (p *PushEvent) GetPushID() int { +func (p *PushEvent) GetPushID() int64 { if p == nil || p.PushID == nil { return 0 } @@ -4372,6 +8028,22 @@ func (p *PushEvent) GetRef() string { return *p.Ref } +// GetRepo returns the Repo field. +func (p *PushEvent) GetRepo() *PushEventRepository { + if p == nil { + return nil + } + return p.Repo +} + +// GetSender returns the Sender field. +func (p *PushEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetSize returns the Size field if it's non-nil, zero value otherwise. func (p *PushEvent) GetSize() int { if p == nil || p.Size == nil { @@ -4380,6 +8052,22 @@ func (p *PushEvent) GetSize() int { return *p.Size } +// GetAuthor returns the Author field. +func (p *PushEventCommit) GetAuthor() *CommitAuthor { + if p == nil { + return nil + } + return p.Author +} + +// GetCommitter returns the Committer field. +func (p *PushEventCommit) GetCommitter() *CommitAuthor { + if p == nil { + return nil + } + return p.Committer +} + // GetDistinct returns the Distinct field if it's non-nil, zero value otherwise. func (p *PushEventCommit) GetDistinct() bool { if p == nil || p.Distinct == nil { @@ -4573,7 +8261,7 @@ func (p *PushEventRepository) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (p *PushEventRepository) GetID() int { +func (p *PushEventRepository) GetID() int64 { if p == nil || p.ID == nil { return 0 } @@ -4604,6 +8292,14 @@ func (p *PushEventRepository) GetName() string { return *p.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *PushEventRepository) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetOpenIssuesCount returns the OpenIssuesCount field if it's non-nil, zero value otherwise. func (p *PushEventRepository) GetOpenIssuesCount() int { if p == nil || p.OpenIssuesCount == nil { @@ -4620,6 +8316,14 @@ func (p *PushEventRepository) GetOrganization() string { return *p.Organization } +// GetOwner returns the Owner field. +func (p *PushEventRepository) GetOwner() *User { + if p == nil { + return nil + } + return p.Owner +} + // GetPrivate returns the Private field if it's non-nil, zero value otherwise. func (p *PushEventRepository) GetPrivate() bool { if p == nil || p.Private == nil { @@ -4700,6 +8404,22 @@ func (p *PushEventRepository) GetWatchersCount() int { return *p.WatchersCount } +// GetCore returns the Core field. +func (r *RateLimits) GetCore() *Rate { + if r == nil { + return nil + } + return r.Core +} + +// GetSearch returns the Search field. +func (r *RateLimits) GetSearch() *Rate { + if r == nil { + return nil + } + return r.Search +} + // GetContent returns the Content field if it's non-nil, zero value otherwise. func (r *Reaction) GetContent() string { if r == nil || r.Content == nil { @@ -4709,13 +8429,29 @@ func (r *Reaction) GetContent() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *Reaction) GetID() int { +func (r *Reaction) GetID() int64 { if r == nil || r.ID == nil { return 0 } return *r.ID } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *Reaction) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + +// GetUser returns the User field. +func (r *Reaction) GetUser() *User { + if r == nil { + return nil + } + return r.User +} + // GetConfused returns the Confused field if it's non-nil, zero value otherwise. func (r *Reactions) GetConfused() int { if r == nil || r.Confused == nil { @@ -4780,6 +8516,22 @@ func (r *Reactions) GetURL() string { return *r.URL } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *Reference) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + +// GetObject returns the Object field. +func (r *Reference) GetObject() *GitObject { + if r == nil { + return nil + } + return r.Object +} + // GetRef returns the Ref field if it's non-nil, zero value otherwise. func (r *Reference) GetRef() string { if r == nil || r.Ref == nil { @@ -4829,7 +8581,7 @@ func (r *ReleaseAsset) GetDownloadCount() int { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *ReleaseAsset) GetID() int { +func (r *ReleaseAsset) GetID() int64 { if r == nil || r.ID == nil { return 0 } @@ -4852,6 +8604,14 @@ func (r *ReleaseAsset) GetName() string { return *r.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *ReleaseAsset) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + // GetSize returns the Size field if it's non-nil, zero value otherwise. func (r *ReleaseAsset) GetSize() int { if r == nil || r.Size == nil { @@ -4876,6 +8636,14 @@ func (r *ReleaseAsset) GetUpdatedAt() Timestamp { return *r.UpdatedAt } +// GetUploader returns the Uploader field. +func (r *ReleaseAsset) GetUploader() *User { + if r == nil { + return nil + } + return r.Uploader +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (r *ReleaseAsset) GetURL() string { if r == nil || r.URL == nil { @@ -4892,6 +8660,38 @@ func (r *ReleaseEvent) GetAction() string { return *r.Action } +// GetInstallation returns the Installation field. +func (r *ReleaseEvent) GetInstallation() *Installation { + if r == nil { + return nil + } + return r.Installation +} + +// GetRelease returns the Release field. +func (r *ReleaseEvent) GetRelease() *RepositoryRelease { + if r == nil { + return nil + } + return r.Release +} + +// GetRepo returns the Repo field. +func (r *ReleaseEvent) GetRepo() *Repository { + if r == nil { + return nil + } + return r.Repo +} + +// GetSender returns the Sender field. +func (r *ReleaseEvent) GetSender() *User { + if r == nil { + return nil + } + return r.Sender +} + // GetFrom returns the From field if it's non-nil, zero value otherwise. func (r *Rename) GetFrom() string { if r == nil || r.From == nil { @@ -4948,6 +8748,14 @@ func (r *Repository) GetAllowSquashMerge() bool { return *r.AllowSquashMerge } +// GetArchived returns the Archived field if it's non-nil, zero value otherwise. +func (r *Repository) GetArchived() bool { + if r == nil || r.Archived == nil { + return false + } + return *r.Archived +} + // GetArchiveURL returns the ArchiveURL field if it's non-nil, zero value otherwise. func (r *Repository) GetArchiveURL() string { if r == nil || r.ArchiveURL == nil { @@ -4996,6 +8804,14 @@ func (r *Repository) GetCloneURL() string { return *r.CloneURL } +// GetCodeOfConduct returns the CodeOfConduct field. +func (r *Repository) GetCodeOfConduct() *CodeOfConduct { + if r == nil { + return nil + } + return r.CodeOfConduct +} + // GetCollaboratorsURL returns the CollaboratorsURL field if it's non-nil, zero value otherwise. func (r *Repository) GetCollaboratorsURL() string { if r == nil || r.CollaboratorsURL == nil { @@ -5188,6 +9004,14 @@ func (r *Repository) GetHasPages() bool { return *r.HasPages } +// GetHasProjects returns the HasProjects field if it's non-nil, zero value otherwise. +func (r *Repository) GetHasProjects() bool { + if r == nil || r.HasProjects == nil { + return false + } + return *r.HasProjects +} + // GetHasWiki returns the HasWiki field if it's non-nil, zero value otherwise. func (r *Repository) GetHasWiki() bool { if r == nil || r.HasWiki == nil { @@ -5221,7 +9045,7 @@ func (r *Repository) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *Repository) GetID() int { +func (r *Repository) GetID() int64 { if r == nil || r.ID == nil { return 0 } @@ -5284,6 +9108,14 @@ func (r *Repository) GetLanguagesURL() string { return *r.LanguagesURL } +// GetLicense returns the License field. +func (r *Repository) GetLicense() *License { + if r == nil { + return nil + } + return r.License +} + // GetLicenseTemplate returns the LicenseTemplate field if it's non-nil, zero value otherwise. func (r *Repository) GetLicenseTemplate() string { if r == nil || r.LicenseTemplate == nil { @@ -5340,6 +9172,14 @@ func (r *Repository) GetNetworkCount() int { return *r.NetworkCount } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *Repository) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + // GetNotificationsURL returns the NotificationsURL field if it's non-nil, zero value otherwise. func (r *Repository) GetNotificationsURL() string { if r == nil || r.NotificationsURL == nil { @@ -5356,6 +9196,30 @@ func (r *Repository) GetOpenIssuesCount() int { return *r.OpenIssuesCount } +// GetOrganization returns the Organization field. +func (r *Repository) GetOrganization() *Organization { + if r == nil { + return nil + } + return r.Organization +} + +// GetOwner returns the Owner field. +func (r *Repository) GetOwner() *User { + if r == nil { + return nil + } + return r.Owner +} + +// GetParent returns the Parent field. +func (r *Repository) GetParent() *Repository { + if r == nil { + return nil + } + return r.Parent +} + // GetPermissions returns the Permissions field if it's non-nil, zero value otherwise. func (r *Repository) GetPermissions() map[string]bool { if r == nil || r.Permissions == nil { @@ -5404,6 +9268,14 @@ func (r *Repository) GetSize() int { return *r.Size } +// GetSource returns the Source field. +func (r *Repository) GetSource() *Repository { + if r == nil { + return nil + } + return r.Source +} + // GetSSHURL returns the SSHURL field if it's non-nil, zero value otherwise. func (r *Repository) GetSSHURL() string { if r == nil || r.SSHURL == nil { @@ -5477,7 +9349,7 @@ func (r *Repository) GetTagsURL() string { } // GetTeamID returns the TeamID field if it's non-nil, zero value otherwise. -func (r *Repository) GetTeamID() int { +func (r *Repository) GetTeamID() int64 { if r == nil || r.TeamID == nil { return 0 } @@ -5557,7 +9429,7 @@ func (r *RepositoryComment) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepositoryComment) GetID() int { +func (r *RepositoryComment) GetID() int64 { if r == nil || r.ID == nil { return 0 } @@ -5580,6 +9452,14 @@ func (r *RepositoryComment) GetPosition() int { return *r.Position } +// GetReactions returns the Reactions field. +func (r *RepositoryComment) GetReactions() *Reactions { + if r == nil { + return nil + } + return r.Reactions +} + // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. func (r *RepositoryComment) GetUpdatedAt() time.Time { if r == nil || r.UpdatedAt == nil { @@ -5596,6 +9476,22 @@ func (r *RepositoryComment) GetURL() string { return *r.URL } +// GetUser returns the User field. +func (r *RepositoryComment) GetUser() *User { + if r == nil { + return nil + } + return r.User +} + +// GetAuthor returns the Author field. +func (r *RepositoryCommit) GetAuthor() *User { + if r == nil { + return nil + } + return r.Author +} + // GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. func (r *RepositoryCommit) GetCommentsURL() string { if r == nil || r.CommentsURL == nil { @@ -5604,6 +9500,22 @@ func (r *RepositoryCommit) GetCommentsURL() string { return *r.CommentsURL } +// GetCommit returns the Commit field. +func (r *RepositoryCommit) GetCommit() *Commit { + if r == nil { + return nil + } + return r.Commit +} + +// GetCommitter returns the Committer field. +func (r *RepositoryCommit) GetCommitter() *User { + if r == nil { + return nil + } + return r.Committer +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (r *RepositoryCommit) GetHTMLURL() string { if r == nil || r.HTMLURL == nil { @@ -5620,6 +9532,14 @@ func (r *RepositoryCommit) GetSHA() string { return *r.SHA } +// GetStats returns the Stats field. +func (r *RepositoryCommit) GetStats() *CommitStats { + if r == nil { + return nil + } + return r.Stats +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (r *RepositoryCommit) GetURL() string { if r == nil || r.URL == nil { @@ -5708,6 +9628,14 @@ func (r *RepositoryContent) GetURL() string { return *r.URL } +// GetAuthor returns the Author field. +func (r *RepositoryContentFileOptions) GetAuthor() *CommitAuthor { + if r == nil { + return nil + } + return r.Author +} + // GetBranch returns the Branch field if it's non-nil, zero value otherwise. func (r *RepositoryContentFileOptions) GetBranch() string { if r == nil || r.Branch == nil { @@ -5716,6 +9644,14 @@ func (r *RepositoryContentFileOptions) GetBranch() string { return *r.Branch } +// GetCommitter returns the Committer field. +func (r *RepositoryContentFileOptions) GetCommitter() *CommitAuthor { + if r == nil { + return nil + } + return r.Committer +} + // GetMessage returns the Message field if it's non-nil, zero value otherwise. func (r *RepositoryContentFileOptions) GetMessage() string { if r == nil || r.Message == nil { @@ -5732,6 +9668,14 @@ func (r *RepositoryContentFileOptions) GetSHA() string { return *r.SHA } +// GetContent returns the Content field. +func (r *RepositoryContentResponse) GetContent() *RepositoryContent { + if r == nil { + return nil + } + return r.Content +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (r *RepositoryEvent) GetAction() string { if r == nil || r.Action == nil { @@ -5740,6 +9684,38 @@ func (r *RepositoryEvent) GetAction() string { return *r.Action } +// GetInstallation returns the Installation field. +func (r *RepositoryEvent) GetInstallation() *Installation { + if r == nil { + return nil + } + return r.Installation +} + +// GetOrg returns the Org field. +func (r *RepositoryEvent) GetOrg() *Organization { + if r == nil { + return nil + } + return r.Org +} + +// GetRepo returns the Repo field. +func (r *RepositoryEvent) GetRepo() *Repository { + if r == nil { + return nil + } + return r.Repo +} + +// GetSender returns the Sender field. +func (r *RepositoryEvent) GetSender() *User { + if r == nil { + return nil + } + return r.Sender +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (r *RepositoryInvitation) GetCreatedAt() Timestamp { if r == nil || r.CreatedAt == nil { @@ -5757,13 +9733,29 @@ func (r *RepositoryInvitation) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepositoryInvitation) GetID() int { +func (r *RepositoryInvitation) GetID() int64 { if r == nil || r.ID == nil { return 0 } return *r.ID } +// GetInvitee returns the Invitee field. +func (r *RepositoryInvitation) GetInvitee() *User { + if r == nil { + return nil + } + return r.Invitee +} + +// GetInviter returns the Inviter field. +func (r *RepositoryInvitation) GetInviter() *User { + if r == nil { + return nil + } + return r.Inviter +} + // GetPermissions returns the Permissions field if it's non-nil, zero value otherwise. func (r *RepositoryInvitation) GetPermissions() string { if r == nil || r.Permissions == nil { @@ -5772,6 +9764,14 @@ func (r *RepositoryInvitation) GetPermissions() string { return *r.Permissions } +// GetRepo returns the Repo field. +func (r *RepositoryInvitation) GetRepo() *Repository { + if r == nil { + return nil + } + return r.Repo +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (r *RepositoryInvitation) GetURL() string { if r == nil || r.URL == nil { @@ -5820,6 +9820,14 @@ func (r *RepositoryLicense) GetHTMLURL() string { return *r.HTMLURL } +// GetLicense returns the License field. +func (r *RepositoryLicense) GetLicense() *License { + if r == nil { + return nil + } + return r.License +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (r *RepositoryLicense) GetName() string { if r == nil || r.Name == nil { @@ -5900,6 +9908,14 @@ func (r *RepositoryPermissionLevel) GetPermission() string { return *r.Permission } +// GetUser returns the User field. +func (r *RepositoryPermissionLevel) GetUser() *User { + if r == nil { + return nil + } + return r.User +} + // GetAssetsURL returns the AssetsURL field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetAssetsURL() string { if r == nil || r.AssetsURL == nil { @@ -5908,6 +9924,14 @@ func (r *RepositoryRelease) GetAssetsURL() string { return *r.AssetsURL } +// GetAuthor returns the Author field. +func (r *RepositoryRelease) GetAuthor() *User { + if r == nil { + return nil + } + return r.Author +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetBody() string { if r == nil || r.Body == nil { @@ -5941,7 +9965,7 @@ func (r *RepositoryRelease) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetID() int { +func (r *RepositoryRelease) GetID() int64 { if r == nil || r.ID == nil { return 0 } @@ -5956,6 +9980,14 @@ func (r *RepositoryRelease) GetName() string { return *r.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + // GetPrerelease returns the Prerelease field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetPrerelease() bool { if r == nil || r.Prerelease == nil { @@ -6020,6 +10052,14 @@ func (r *RepositoryRelease) GetZipballURL() string { return *r.ZipballURL } +// GetCommit returns the Commit field. +func (r *RepositoryTag) GetCommit() *Commit { + if r == nil { + return nil + } + return r.Commit +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (r *RepositoryTag) GetName() string { if r == nil || r.Name == nil { @@ -6044,6 +10084,62 @@ func (r *RepositoryTag) GetZipballURL() string { return *r.ZipballURL } +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (r *RepositoryVulnerabilityAlertEvent) GetAction() string { + if r == nil || r.Action == nil { + return "" + } + return *r.Action +} + +// GetForkRepos returns the ForkRepos field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetForkRepos() int { + if r == nil || r.ForkRepos == nil { + return 0 + } + return *r.ForkRepos +} + +// GetOrgRepos returns the OrgRepos field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetOrgRepos() int { + if r == nil || r.OrgRepos == nil { + return 0 + } + return *r.OrgRepos +} + +// GetRootRepos returns the RootRepos field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetRootRepos() int { + if r == nil || r.RootRepos == nil { + return 0 + } + return *r.RootRepos +} + +// GetTotalPushes returns the TotalPushes field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetTotalPushes() int { + if r == nil || r.TotalPushes == nil { + return 0 + } + return *r.TotalPushes +} + +// GetTotalRepos returns the TotalRepos field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetTotalRepos() int { + if r == nil || r.TotalRepos == nil { + return 0 + } + return *r.TotalRepos +} + +// GetTotalWikis returns the TotalWikis field if it's non-nil, zero value otherwise. +func (r *RepoStats) GetTotalWikis() int { + if r == nil || r.TotalWikis == nil { + return 0 + } + return *r.TotalWikis +} + // GetContext returns the Context field if it's non-nil, zero value otherwise. func (r *RepoStatus) GetContext() string { if r == nil || r.Context == nil { @@ -6060,6 +10156,14 @@ func (r *RepoStatus) GetCreatedAt() time.Time { return *r.CreatedAt } +// GetCreator returns the Creator field. +func (r *RepoStatus) GetCreator() *User { + if r == nil { + return nil + } + return r.Creator +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (r *RepoStatus) GetDescription() string { if r == nil || r.Description == nil { @@ -6069,7 +10173,7 @@ func (r *RepoStatus) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepoStatus) GetID() int { +func (r *RepoStatus) GetID() int64 { if r == nil || r.ID == nil { return 0 } @@ -6108,6 +10212,14 @@ func (r *RepoStatus) GetURL() string { return *r.URL } +// GetStrict returns the Strict field if it's non-nil, zero value otherwise. +func (r *RequiredStatusChecksRequest) GetStrict() bool { + if r == nil || r.Strict == nil { + return false + } + return *r.Strict +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (s *ServiceHook) GetName() string { if s == nil || s.Name == nil { @@ -6116,6 +10228,22 @@ func (s *ServiceHook) GetName() string { return *s.Name } +// GetEnabled returns the Enabled field if it's non-nil, zero value otherwise. +func (s *SignaturesProtectedBranch) GetEnabled() bool { + if s == nil || s.Enabled == nil { + return false + } + return *s.Enabled +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (s *SignaturesProtectedBranch) GetURL() string { + if s == nil || s.URL == nil { + return "" + } + return *s.URL +} + // GetPayload returns the Payload field if it's non-nil, zero value otherwise. func (s *SignatureVerification) GetPayload() string { if s == nil || s.Payload == nil { @@ -6148,8 +10276,16 @@ func (s *SignatureVerification) GetVerified() bool { return *s.Verified } +// GetActor returns the Actor field. +func (s *Source) GetActor() *User { + if s == nil { + return nil + } + return s.Actor +} + // GetID returns the ID field if it's non-nil, zero value otherwise. -func (s *Source) GetID() int { +func (s *Source) GetID() int64 { if s == nil || s.ID == nil { return 0 } @@ -6173,7 +10309,7 @@ func (s *SourceImportAuthor) GetEmail() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (s *SourceImportAuthor) GetID() int { +func (s *SourceImportAuthor) GetID() int64 { if s == nil || s.ID == nil { return 0 } @@ -6228,6 +10364,22 @@ func (s *Stargazer) GetStarredAt() Timestamp { return *s.StarredAt } +// GetUser returns the User field. +func (s *Stargazer) GetUser() *User { + if s == nil { + return nil + } + return s.User +} + +// GetRepository returns the Repository field. +func (s *StarredRepository) GetRepository() *Repository { + if s == nil { + return nil + } + return s.Repository +} + // GetStarredAt returns the StarredAt field if it's non-nil, zero value otherwise. func (s *StarredRepository) GetStarredAt() Timestamp { if s == nil || s.StarredAt == nil { @@ -6236,20 +10388,12 @@ func (s *StarredRepository) GetStarredAt() Timestamp { return *s.StarredAt } -// GetExcludeAttachments returns the ExcludeAttachments field if it's non-nil, zero value otherwise. -func (s *startMigration) GetExcludeAttachments() bool { - if s == nil || s.ExcludeAttachments == nil { - return false +// GetCommit returns the Commit field. +func (s *StatusEvent) GetCommit() *RepositoryCommit { + if s == nil { + return nil } - return *s.ExcludeAttachments -} - -// GetLockRepositories returns the LockRepositories field if it's non-nil, zero value otherwise. -func (s *startMigration) GetLockRepositories() bool { - if s == nil || s.LockRepositories == nil { - return false - } - return *s.LockRepositories + return s.Commit } // GetContext returns the Context field if it's non-nil, zero value otherwise. @@ -6277,13 +10421,21 @@ func (s *StatusEvent) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (s *StatusEvent) GetID() int { +func (s *StatusEvent) GetID() int64 { if s == nil || s.ID == nil { return 0 } return *s.ID } +// GetInstallation returns the Installation field. +func (s *StatusEvent) GetInstallation() *Installation { + if s == nil { + return nil + } + return s.Installation +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (s *StatusEvent) GetName() string { if s == nil || s.Name == nil { @@ -6292,6 +10444,22 @@ func (s *StatusEvent) GetName() string { return *s.Name } +// GetRepo returns the Repo field. +func (s *StatusEvent) GetRepo() *Repository { + if s == nil { + return nil + } + return s.Repo +} + +// GetSender returns the Sender field. +func (s *StatusEvent) GetSender() *User { + if s == nil { + return nil + } + return s.Sender +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (s *StatusEvent) GetSHA() string { if s == nil || s.SHA == nil { @@ -6388,6 +10556,22 @@ func (t *Tag) GetMessage() string { return *t.Message } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (t *Tag) GetNodeID() string { + if t == nil || t.NodeID == nil { + return "" + } + return *t.NodeID +} + +// GetObject returns the Object field. +func (t *Tag) GetObject() *GitObject { + if t == nil { + return nil + } + return t.Object +} + // GetSHA returns the SHA field if it's non-nil, zero value otherwise. func (t *Tag) GetSHA() string { if t == nil || t.SHA == nil { @@ -6404,6 +10588,14 @@ func (t *Tag) GetTag() string { return *t.Tag } +// GetTagger returns the Tagger field. +func (t *Tag) GetTagger() *CommitAuthor { + if t == nil { + return nil + } + return t.Tagger +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (t *Tag) GetURL() string { if t == nil || t.URL == nil { @@ -6412,6 +10604,14 @@ func (t *Tag) GetURL() string { return *t.URL } +// GetVerification returns the Verification field. +func (t *Tag) GetVerification() *SignatureVerification { + if t == nil { + return nil + } + return t.Verification +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (t *Team) GetDescription() string { if t == nil || t.Description == nil { @@ -6421,7 +10621,7 @@ func (t *Team) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (t *Team) GetID() int { +func (t *Team) GetID() int64 { if t == nil || t.ID == nil { return 0 } @@ -6460,6 +10660,22 @@ func (t *Team) GetName() string { return *t.Name } +// GetOrganization returns the Organization field. +func (t *Team) GetOrganization() *Organization { + if t == nil { + return nil + } + return t.Organization +} + +// GetParent returns the Parent field. +func (t *Team) GetParent() *Team { + if t == nil { + return nil + } + return t.Parent +} + // GetPermission returns the Permission field if it's non-nil, zero value otherwise. func (t *Team) GetPermission() string { if t == nil || t.Permission == nil { @@ -6508,6 +10724,190 @@ func (t *Team) GetURL() string { return *t.URL } +// GetInstallation returns the Installation field. +func (t *TeamAddEvent) GetInstallation() *Installation { + if t == nil { + return nil + } + return t.Installation +} + +// GetOrg returns the Org field. +func (t *TeamAddEvent) GetOrg() *Organization { + if t == nil { + return nil + } + return t.Org +} + +// GetRepo returns the Repo field. +func (t *TeamAddEvent) GetRepo() *Repository { + if t == nil { + return nil + } + return t.Repo +} + +// GetSender returns the Sender field. +func (t *TeamAddEvent) GetSender() *User { + if t == nil { + return nil + } + return t.Sender +} + +// GetTeam returns the Team field. +func (t *TeamAddEvent) GetTeam() *Team { + if t == nil { + return nil + } + return t.Team +} + +// GetAuthor returns the Author field. +func (t *TeamDiscussion) GetAuthor() *User { + if t == nil { + return nil + } + return t.Author +} + +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetBody() string { + if t == nil || t.Body == nil { + return "" + } + return *t.Body +} + +// GetBodyHTML returns the BodyHTML field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetBodyHTML() string { + if t == nil || t.BodyHTML == nil { + return "" + } + return *t.BodyHTML +} + +// GetBodyVersion returns the BodyVersion field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetBodyVersion() string { + if t == nil || t.BodyVersion == nil { + return "" + } + return *t.BodyVersion +} + +// GetCommentsCount returns the CommentsCount field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetCommentsCount() int { + if t == nil || t.CommentsCount == nil { + return 0 + } + return *t.CommentsCount +} + +// GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetCommentsURL() string { + if t == nil || t.CommentsURL == nil { + return "" + } + return *t.CommentsURL +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetCreatedAt() Timestamp { + if t == nil || t.CreatedAt == nil { + return Timestamp{} + } + return *t.CreatedAt +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetHTMLURL() string { + if t == nil || t.HTMLURL == nil { + return "" + } + return *t.HTMLURL +} + +// GetLastEditedAt returns the LastEditedAt field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetLastEditedAt() Timestamp { + if t == nil || t.LastEditedAt == nil { + return Timestamp{} + } + return *t.LastEditedAt +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetNodeID() string { + if t == nil || t.NodeID == nil { + return "" + } + return *t.NodeID +} + +// GetNumber returns the Number field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetNumber() int { + if t == nil || t.Number == nil { + return 0 + } + return *t.Number +} + +// GetPinned returns the Pinned field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetPinned() bool { + if t == nil || t.Pinned == nil { + return false + } + return *t.Pinned +} + +// GetPrivate returns the Private field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetPrivate() bool { + if t == nil || t.Private == nil { + return false + } + return *t.Private +} + +// GetReactions returns the Reactions field. +func (t *TeamDiscussion) GetReactions() *Reactions { + if t == nil { + return nil + } + return t.Reactions +} + +// GetTeamURL returns the TeamURL field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetTeamURL() string { + if t == nil || t.TeamURL == nil { + return "" + } + return *t.TeamURL +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetTitle() string { + if t == nil || t.Title == nil { + return "" + } + return *t.Title +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetUpdatedAt() Timestamp { + if t == nil || t.UpdatedAt == nil { + return Timestamp{} + } + return *t.UpdatedAt +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (t *TeamDiscussion) GetURL() string { + if t == nil || t.URL == nil { + return "" + } + return *t.URL +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (t *TeamEvent) GetAction() string { if t == nil || t.Action == nil { @@ -6516,6 +10916,54 @@ func (t *TeamEvent) GetAction() string { return *t.Action } +// GetChanges returns the Changes field. +func (t *TeamEvent) GetChanges() *TeamChange { + if t == nil { + return nil + } + return t.Changes +} + +// GetInstallation returns the Installation field. +func (t *TeamEvent) GetInstallation() *Installation { + if t == nil { + return nil + } + return t.Installation +} + +// GetOrg returns the Org field. +func (t *TeamEvent) GetOrg() *Organization { + if t == nil { + return nil + } + return t.Org +} + +// GetRepo returns the Repo field. +func (t *TeamEvent) GetRepo() *Repository { + if t == nil { + return nil + } + return t.Repo +} + +// GetSender returns the Sender field. +func (t *TeamEvent) GetSender() *User { + if t == nil { + return nil + } + return t.Sender +} + +// GetTeam returns the Team field. +func (t *TeamEvent) GetTeam() *Team { + if t == nil { + return nil + } + return t.Team +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (t *TeamLDAPMapping) GetDescription() string { if t == nil || t.Description == nil { @@ -6525,7 +10973,7 @@ func (t *TeamLDAPMapping) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (t *TeamLDAPMapping) GetID() int { +func (t *TeamLDAPMapping) GetID() int64 { if t == nil || t.ID == nil { return 0 } @@ -6628,6 +11076,22 @@ func (t *TextMatch) GetProperty() string { return *t.Property } +// GetActor returns the Actor field. +func (t *Timeline) GetActor() *User { + if t == nil { + return nil + } + return t.Actor +} + +// GetAssignee returns the Assignee field. +func (t *Timeline) GetAssignee() *User { + if t == nil { + return nil + } + return t.Assignee +} + // GetCommitID returns the CommitID field if it's non-nil, zero value otherwise. func (t *Timeline) GetCommitID() string { if t == nil || t.CommitID == nil { @@ -6661,13 +11125,45 @@ func (t *Timeline) GetEvent() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (t *Timeline) GetID() int { +func (t *Timeline) GetID() int64 { if t == nil || t.ID == nil { return 0 } return *t.ID } +// GetLabel returns the Label field. +func (t *Timeline) GetLabel() *Label { + if t == nil { + return nil + } + return t.Label +} + +// GetMilestone returns the Milestone field. +func (t *Timeline) GetMilestone() *Milestone { + if t == nil { + return nil + } + return t.Milestone +} + +// GetRename returns the Rename field. +func (t *Timeline) GetRename() *Rename { + if t == nil { + return nil + } + return t.Rename +} + +// GetSource returns the Source field. +func (t *Timeline) GetSource() *Source { + if t == nil { + return nil + } + return t.Source +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (t *Timeline) GetURL() string { if t == nil || t.URL == nil { @@ -6796,6 +11292,14 @@ func (t *Tree) GetSHA() string { return *t.SHA } +// GetTruncated returns the Truncated field if it's non-nil, zero value otherwise. +func (t *Tree) GetTruncated() bool { + if t == nil || t.Truncated == nil { + return false + } + return *t.Truncated +} + // GetContent returns the Content field if it's non-nil, zero value otherwise. func (t *TreeEntry) GetContent() string { if t == nil || t.Content == nil { @@ -6852,20 +11356,68 @@ func (t *TreeEntry) GetURL() string { return *t.URL } -// GetForce returns the Force field if it's non-nil, zero value otherwise. -func (u *updateRefRequest) GetForce() bool { - if u == nil || u.Force == nil { - return false +// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetCompletedAt() Timestamp { + if u == nil || u.CompletedAt == nil { + return Timestamp{} } - return *u.Force + return *u.CompletedAt } -// GetSHA returns the SHA field if it's non-nil, zero value otherwise. -func (u *updateRefRequest) GetSHA() string { - if u == nil || u.SHA == nil { +// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetConclusion() string { + if u == nil || u.Conclusion == nil { return "" } - return *u.SHA + return *u.Conclusion +} + +// GetDetailsURL returns the DetailsURL field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetDetailsURL() string { + if u == nil || u.DetailsURL == nil { + return "" + } + return *u.DetailsURL +} + +// GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetExternalID() string { + if u == nil || u.ExternalID == nil { + return "" + } + return *u.ExternalID +} + +// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetHeadBranch() string { + if u == nil || u.HeadBranch == nil { + return "" + } + return *u.HeadBranch +} + +// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetHeadSHA() string { + if u == nil || u.HeadSHA == nil { + return "" + } + return *u.HeadSHA +} + +// GetOutput returns the Output field. +func (u *UpdateCheckRunOptions) GetOutput() *CheckRunOutput { + if u == nil { + return nil + } + return u.Output +} + +// GetStatus returns the Status field if it's non-nil, zero value otherwise. +func (u *UpdateCheckRunOptions) GetStatus() string { + if u == nil || u.Status == nil { + return "" + } + return *u.Status } // GetAvatarURL returns the AvatarURL field if it's non-nil, zero value otherwise. @@ -7005,7 +11557,7 @@ func (u *User) GetHTMLURL() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (u *User) GetID() int { +func (u *User) GetID() int64 { if u == nil || u.ID == nil { return 0 } @@ -7036,6 +11588,14 @@ func (u *User) GetName() string { return *u.Name } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (u *User) GetNodeID() string { + if u == nil || u.NodeID == nil { + return "" + } + return *u.NodeID +} + // GetOrganizationsURL returns the OrganizationsURL field if it's non-nil, zero value otherwise. func (u *User) GetOrganizationsURL() string { if u == nil || u.OrganizationsURL == nil { @@ -7060,6 +11620,14 @@ func (u *User) GetPermissions() map[string]bool { return *u.Permissions } +// GetPlan returns the Plan field. +func (u *User) GetPlan() *Plan { + if u == nil { + return nil + } + return u.Plan +} + // GetPrivateGists returns the PrivateGists field if it's non-nil, zero value otherwise. func (u *User) GetPrivateGists() int { if u == nil || u.PrivateGists == nil { @@ -7140,6 +11708,14 @@ func (u *User) GetTotalPrivateRepos() int { return *u.TotalPrivateRepos } +// GetTwoFactorAuthentication returns the TwoFactorAuthentication field if it's non-nil, zero value otherwise. +func (u *User) GetTwoFactorAuthentication() bool { + if u == nil || u.TwoFactorAuthentication == nil { + return false + } + return *u.TwoFactorAuthentication +} + // GetType returns the Type field if it's non-nil, zero value otherwise. func (u *User) GetType() string { if u == nil || u.Type == nil { @@ -7164,6 +11740,22 @@ func (u *User) GetURL() string { return *u.URL } +// GetMessage returns the Message field if it's non-nil, zero value otherwise. +func (u *UserContext) GetMessage() string { + if u == nil || u.Message == nil { + return "" + } + return *u.Message +} + +// GetOcticon returns the Octicon field if it's non-nil, zero value otherwise. +func (u *UserContext) GetOcticon() string { + if u == nil || u.Octicon == nil { + return "" + } + return *u.Octicon +} + // GetEmail returns the Email field if it's non-nil, zero value otherwise. func (u *UserEmail) GetEmail() string { if u == nil || u.Email == nil { @@ -7237,7 +11829,7 @@ func (u *UserLDAPMapping) GetGravatarID() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (u *UserLDAPMapping) GetID() int { +func (u *UserLDAPMapping) GetID() int64 { if u == nil || u.ID == nil { return 0 } @@ -7324,6 +11916,70 @@ func (u *UserLDAPMapping) GetURL() string { return *u.URL } +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetCreatedAt() string { + if u == nil || u.CreatedAt == nil { + return "" + } + return *u.CreatedAt +} + +// GetExcludeAttachments returns the ExcludeAttachments field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetExcludeAttachments() bool { + if u == nil || u.ExcludeAttachments == nil { + return false + } + return *u.ExcludeAttachments +} + +// GetGUID returns the GUID field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetGUID() string { + if u == nil || u.GUID == nil { + return "" + } + return *u.GUID +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetID() int64 { + if u == nil || u.ID == nil { + return 0 + } + return *u.ID +} + +// GetLockRepositories returns the LockRepositories field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetLockRepositories() bool { + if u == nil || u.LockRepositories == nil { + return false + } + return *u.LockRepositories +} + +// GetState returns the State field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetState() string { + if u == nil || u.State == nil { + return "" + } + return *u.State +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetUpdatedAt() string { + if u == nil || u.UpdatedAt == nil { + return "" + } + return *u.UpdatedAt +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (u *UserMigration) GetURL() string { + if u == nil || u.URL == nil { + return "" + } + return *u.URL +} + // GetIncompleteResults returns the IncompleteResults field if it's non-nil, zero value otherwise. func (u *UsersSearchResult) GetIncompleteResults() bool { if u == nil || u.IncompleteResults == nil { @@ -7340,6 +11996,30 @@ func (u *UsersSearchResult) GetTotal() int { return *u.Total } +// GetAdminUsers returns the AdminUsers field if it's non-nil, zero value otherwise. +func (u *UserStats) GetAdminUsers() int { + if u == nil || u.AdminUsers == nil { + return 0 + } + return *u.AdminUsers +} + +// GetSuspendedUsers returns the SuspendedUsers field if it's non-nil, zero value otherwise. +func (u *UserStats) GetSuspendedUsers() int { + if u == nil || u.SuspendedUsers == nil { + return 0 + } + return *u.SuspendedUsers +} + +// GetTotalUsers returns the TotalUsers field if it's non-nil, zero value otherwise. +func (u *UserStats) GetTotalUsers() int { + if u == nil || u.TotalUsers == nil { + return 0 + } + return *u.TotalUsers +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (w *WatchEvent) GetAction() string { if w == nil || w.Action == nil { @@ -7348,6 +12028,30 @@ func (w *WatchEvent) GetAction() string { return *w.Action } +// GetInstallation returns the Installation field. +func (w *WatchEvent) GetInstallation() *Installation { + if w == nil { + return nil + } + return w.Installation +} + +// GetRepo returns the Repo field. +func (w *WatchEvent) GetRepo() *Repository { + if w == nil { + return nil + } + return w.Repo +} + +// GetSender returns the Sender field. +func (w *WatchEvent) GetSender() *User { + if w == nil { + return nil + } + return w.Sender +} + // GetEmail returns the Email field if it's non-nil, zero value otherwise. func (w *WebHookAuthor) GetEmail() string { if w == nil || w.Email == nil { @@ -7372,6 +12076,22 @@ func (w *WebHookAuthor) GetUsername() string { return *w.Username } +// GetAuthor returns the Author field. +func (w *WebHookCommit) GetAuthor() *WebHookAuthor { + if w == nil { + return nil + } + return w.Author +} + +// GetCommitter returns the Committer field. +func (w *WebHookCommit) GetCommitter() *WebHookAuthor { + if w == nil { + return nil + } + return w.Committer +} + // GetDistinct returns the Distinct field if it's non-nil, zero value otherwise. func (w *WebHookCommit) GetDistinct() bool { if w == nil || w.Distinct == nil { @@ -7452,6 +12172,22 @@ func (w *WebHookPayload) GetForced() bool { return *w.Forced } +// GetHeadCommit returns the HeadCommit field. +func (w *WebHookPayload) GetHeadCommit() *WebHookCommit { + if w == nil { + return nil + } + return w.HeadCommit +} + +// GetPusher returns the Pusher field. +func (w *WebHookPayload) GetPusher() *User { + if w == nil { + return nil + } + return w.Pusher +} + // GetRef returns the Ref field if it's non-nil, zero value otherwise. func (w *WebHookPayload) GetRef() string { if w == nil || w.Ref == nil { @@ -7460,6 +12196,22 @@ func (w *WebHookPayload) GetRef() string { return *w.Ref } +// GetRepo returns the Repo field. +func (w *WebHookPayload) GetRepo() *Repository { + if w == nil { + return nil + } + return w.Repo +} + +// GetSender returns the Sender field. +func (w *WebHookPayload) GetSender() *User { + if w == nil { + return nil + } + return w.Sender +} + // GetTotal returns the Total field if it's non-nil, zero value otherwise. func (w *WeeklyCommitActivity) GetTotal() int { if w == nil || w.Total == nil { diff --git a/vendor/github.com/google/go-github/github/github.go b/vendor/github.com/google/go-github/github/github.go index ae37ba8f6..9544b5c15 100644 --- a/vendor/github.com/google/go-github/github/github.go +++ b/vendor/github.com/google/go-github/github/github.go @@ -27,10 +27,9 @@ import ( ) const ( - libraryVersion = "12" defaultBaseURL = "https://api.github.com/" uploadBaseURL = "https://uploads.github.com/" - userAgent = "go-github/" + libraryVersion + userAgent = "go-github" headerRateLimit = "X-RateLimit-Limit" headerRateRemaining = "X-RateLimit-Remaining" @@ -46,21 +45,18 @@ const ( // Media Type values to access preview APIs - // https://developer.github.com/changes/2015-03-09-licenses-api/ - mediaTypeLicensesPreview = "application/vnd.github.drax-preview+json" - // https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/ mediaTypeStarringPreview = "application/vnd.github.v3.star+json" - // https://developer.github.com/changes/2015-11-11-protected-branches-api/ - mediaTypeProtectedBranchesPreview = "application/vnd.github.loki-preview+json" - // https://help.github.com/enterprise/2.4/admin/guides/migrations/exporting-the-github-com-organization-s-repositories/ mediaTypeMigrationsPreview = "application/vnd.github.wyandotte-preview+json" // https://developer.github.com/changes/2016-04-06-deployment-and-deployment-status-enhancements/ mediaTypeDeploymentStatusPreview = "application/vnd.github.ant-man-preview+json" + // https://developer.github.com/changes/2018-10-16-deployments-environments-states-and-auto-inactive-updates/ + mediaTypeExpandDeploymentStatusPreview = "application/vnd.github.flash-preview+json" + // https://developer.github.com/changes/2016-02-19-source-import-preview-api/ mediaTypeImportPreview = "application/vnd.github.barred-rock-preview" @@ -100,8 +96,41 @@ const ( // https://developer.github.com/changes/2017-07-17-update-topics-on-repositories/ mediaTypeTopicsPreview = "application/vnd.github.mercy-preview+json" - // https://developer.github.com/changes/2017-07-26-team-review-request-thor-preview/ - mediaTypeTeamReviewPreview = "application/vnd.github.thor-preview+json" + // https://developer.github.com/changes/2017-08-30-preview-nested-teams/ + mediaTypeNestedTeamsPreview = "application/vnd.github.hellcat-preview+json" + + // https://developer.github.com/changes/2017-11-09-repository-transfer-api-preview/ + mediaTypeRepositoryTransferPreview = "application/vnd.github.nightshade-preview+json" + + // https://developer.github.com/changes/2018-01-25-organization-invitation-api-preview/ + mediaTypeOrganizationInvitationPreview = "application/vnd.github.dazzler-preview+json" + + // https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/ + mediaTypeRequiredApprovingReviewsPreview = "application/vnd.github.luke-cage-preview+json" + + // https://developer.github.com/changes/2018-02-22-label-description-search-preview/ + mediaTypeLabelDescriptionSearchPreview = "application/vnd.github.symmetra-preview+json" + + // https://developer.github.com/changes/2018-02-07-team-discussions-api/ + mediaTypeTeamDiscussionsPreview = "application/vnd.github.echo-preview+json" + + // https://developer.github.com/changes/2018-03-21-hovercard-api-preview/ + mediaTypeHovercardPreview = "application/vnd.github.hagar-preview+json" + + // https://developer.github.com/changes/2018-01-10-lock-reason-api-preview/ + mediaTypeLockReasonPreview = "application/vnd.github.sailor-v-preview+json" + + // https://developer.github.com/changes/2018-05-07-new-checks-api-public-beta/ + mediaTypeCheckRunsPreview = "application/vnd.github.antiope-preview+json" + + // https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/ + mediaTypePreReceiveHooksPreview = "application/vnd.github.eye-scream-preview" + + // https://developer.github.com/changes/2018-02-22-protected-branches-required-signatures/ + mediaTypeSignaturePreview = "application/vnd.github.zzzax-preview+json" + + // https://developer.github.com/changes/2018-09-05-project-card-events/ + mediaTypeProjectCardDetailsPreview = "application/vnd.github.starfox-preview+json" ) // A Client manages communication with the GitHub API. @@ -130,19 +159,22 @@ type Client struct { Admin *AdminService Apps *AppsService Authorizations *AuthorizationsService + Checks *ChecksService Gists *GistsService Git *GitService Gitignores *GitignoresService Issues *IssuesService + Licenses *LicensesService + Marketplace *MarketplaceService + Migrations *MigrationService Organizations *OrganizationsService Projects *ProjectsService PullRequests *PullRequestsService + Reactions *ReactionsService Repositories *RepositoriesService Search *SearchService + Teams *TeamsService Users *UsersService - Licenses *LicensesService - Migrations *MigrationService - Reactions *ReactionsService } type service struct { @@ -219,11 +251,13 @@ func NewClient(httpClient *http.Client) *Client { c.Admin = (*AdminService)(&c.common) c.Apps = (*AppsService)(&c.common) c.Authorizations = (*AuthorizationsService)(&c.common) + c.Checks = (*ChecksService)(&c.common) c.Gists = (*GistsService)(&c.common) c.Git = (*GitService)(&c.common) c.Gitignores = (*GitignoresService)(&c.common) c.Issues = (*IssuesService)(&c.common) c.Licenses = (*LicensesService)(&c.common) + c.Marketplace = &MarketplaceService{client: c} c.Migrations = (*MigrationService)(&c.common) c.Organizations = (*OrganizationsService)(&c.common) c.Projects = (*ProjectsService)(&c.common) @@ -231,10 +265,42 @@ func NewClient(httpClient *http.Client) *Client { c.Reactions = (*ReactionsService)(&c.common) c.Repositories = (*RepositoriesService)(&c.common) c.Search = (*SearchService)(&c.common) + c.Teams = (*TeamsService)(&c.common) c.Users = (*UsersService)(&c.common) return c } +// NewEnterpriseClient returns a new GitHub API client with provided +// base URL and upload URL (often the same URL). +// If either URL does not have a trailing slash, one is added automatically. +// If a nil httpClient is provided, http.DefaultClient will be used. +// +// Note that NewEnterpriseClient is a convenience helper only; +// its behavior is equivalent to using NewClient, followed by setting +// the BaseURL and UploadURL fields. +func NewEnterpriseClient(baseURL, uploadURL string, httpClient *http.Client) (*Client, error) { + baseEndpoint, err := url.Parse(baseURL) + if err != nil { + return nil, err + } + if !strings.HasSuffix(baseEndpoint.Path, "/") { + baseEndpoint.Path += "/" + } + + uploadEndpoint, err := url.Parse(uploadURL) + if err != nil { + return nil, err + } + if !strings.HasSuffix(uploadEndpoint.Path, "/") { + uploadEndpoint.Path += "/" + } + + c := NewClient(httpClient) + c.BaseURL = baseEndpoint + c.UploadURL = uploadEndpoint + return c, nil +} + // NewRequest creates an API request. A relative URL can be provided in urlStr, // in which case it is resolved relative to the BaseURL of the Client. // Relative URLs should always be specified without a preceding slash. If @@ -252,7 +318,9 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) - err := json.NewEncoder(buf).Encode(body) + enc := json.NewEncoder(buf) + enc.SetEscapeHTML(false) + err := enc.Encode(body) if err != nil { return nil, err } @@ -316,7 +384,9 @@ type Response struct { FirstPage int LastPage int - Rate + // Explicitly specify the Rate type so Rate's String() receiver doesn't + // propagate to Response. + Rate Rate } // newResponse creates a new Response for the provided http.Response. @@ -431,12 +501,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res return nil, err } - - defer func() { - // Drain up to 512 bytes and close the body to let the Transport reuse the connection - io.CopyN(ioutil.Discard, resp.Body, 512) - resp.Body.Close() - }() + defer resp.Body.Close() response := newResponse(resp) @@ -446,8 +511,22 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res err = CheckResponse(resp) if err != nil { - // even though there was an error, we still return the response - // in case the caller wants to inspect it further + // Special case for AcceptedErrors. If an AcceptedError + // has been encountered, the response's payload will be + // added to the AcceptedError and returned. + // + // Issue #1022 + aerr, ok := err.(*AcceptedError) + if ok { + b, readErr := ioutil.ReadAll(resp.Body) + if readErr != nil { + return response, readErr + } + + aerr.Raw = b + return response, aerr + } + return response, err } @@ -455,9 +534,12 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res if w, ok := v.(io.Writer); ok { io.Copy(w, resp.Body) } else { - err = json.NewDecoder(resp.Body).Decode(v) - if err == io.EOF { - err = nil // ignore EOF errors caused by empty response body + decErr := json.NewDecoder(resp.Body).Decode(v) + if decErr == io.EOF { + decErr = nil // ignore EOF errors caused by empty response body + } + if decErr != nil { + err = decErr } } } @@ -547,14 +629,17 @@ func (r *RateLimitError) Error() string { // Technically, 202 Accepted is not a real error, it's just used to // indicate that results are not ready yet, but should be available soon. // The request can be repeated after some time. -type AcceptedError struct{} +type AcceptedError struct { + // Raw contains the response body. + Raw []byte +} func (*AcceptedError) Error() string { return "job scheduled on GitHub side; try again later" } // AbuseRateLimitError occurs when GitHub returns 403 Forbidden response with the -// "documentation_url" field value equal to "https://developer.github.com/v3#abuse-rate-limits". +// "documentation_url" field value equal to "https://developer.github.com/v3/#abuse-rate-limits". type AbuseRateLimitError struct { Response *http.Response // HTTP response that caused this error Message string `json:"message"` // error message @@ -646,7 +731,7 @@ func CheckResponse(r *http.Response) error { Response: errorResponse.Response, Message: errorResponse.Message, } - case r.StatusCode == http.StatusForbidden && errorResponse.DocumentationURL == "https://developer.github.com/v3#abuse-rate-limits": + case r.StatusCode == http.StatusForbidden && strings.HasSuffix(errorResponse.DocumentationURL, "/v3/#abuse-rate-limits"): abuseRateLimitError := &AbuseRateLimitError{ Response: errorResponse.Response, Message: errorResponse.Message, @@ -812,14 +897,21 @@ func (t *UnauthenticatedRateLimitedTransport) RoundTrip(req *http.Request) (*htt // To set extra querystring params, we must make a copy of the Request so // that we don't modify the Request we were given. This is required by the // specification of http.RoundTripper. - req = cloneRequest(req) - q := req.URL.Query() + // + // Since we are going to modify only req.URL here, we only need a deep copy + // of req.URL. + req2 := new(http.Request) + *req2 = *req + req2.URL = new(url.URL) + *req2.URL = *req.URL + + q := req2.URL.Query() q.Set("client_id", t.ClientID) q.Set("client_secret", t.ClientSecret) - req.URL.RawQuery = q.Encode() + req2.URL.RawQuery = q.Encode() // Make the HTTP request. - return t.transport().RoundTrip(req) + return t.transport().RoundTrip(req2) } // Client returns an *http.Client that makes requests which are subject to the @@ -851,12 +943,24 @@ type BasicAuthTransport struct { // RoundTrip implements the RoundTripper interface. func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { - req = cloneRequest(req) // per RoundTrip contract - req.SetBasicAuth(t.Username, t.Password) - if t.OTP != "" { - req.Header.Set(headerOTP, t.OTP) + // To set extra headers, we must make a copy of the Request so + // that we don't modify the Request we were given. This is required by the + // specification of http.RoundTripper. + // + // Since we are going to modify only req.Header here, we only need a deep copy + // of req.Header. + req2 := new(http.Request) + *req2 = *req + req2.Header = make(http.Header, len(req.Header)) + for k, s := range req.Header { + req2.Header[k] = append([]string(nil), s...) } - return t.transport().RoundTrip(req) + + req2.SetBasicAuth(t.Username, t.Password) + if t.OTP != "" { + req2.Header.Set(headerOTP, t.OTP) + } + return t.transport().RoundTrip(req2) } // Client returns an *http.Client that makes requests that are authenticated @@ -872,20 +976,6 @@ func (t *BasicAuthTransport) transport() http.RoundTripper { return http.DefaultTransport } -// cloneRequest returns a clone of the provided *http.Request. The clone is a -// shallow copy of the struct and its Header map. -func cloneRequest(r *http.Request) *http.Request { - // shallow copy of the struct - r2 := new(http.Request) - *r2 = *r - // deep copy of the Header - r2.Header = make(http.Header, len(r.Header)) - for k, s := range r.Header { - r2.Header[k] = append([]string(nil), s...) - } - return r2 -} - // formatRateReset formats d to look like "[rate reset in 2s]" or // "[rate reset in 87m02s]" for the positive durations. And like "[rate limit was reset 87m02s ago]" // for the negative cases. @@ -919,6 +1009,10 @@ func Bool(v bool) *bool { return &v } // to store v and returns a pointer to it. func Int(v int) *int { return &v } +// Int64 is a helper routine that allocates a new int64 value +// to store v and returns a pointer to it. +func Int64(v int64) *int64 { return &v } + // String is a helper routine that allocates a new string value // to store v and returns a pointer to it. func String(v string) *string { return &v } diff --git a/vendor/github.com/google/go-github/github/github_test.go b/vendor/github.com/google/go-github/github/github_test.go index 74d147592..da29e1ecd 100644 --- a/vendor/github.com/google/go-github/github/github_test.go +++ b/vendor/github.com/google/go-github/github/github_test.go @@ -22,35 +22,45 @@ import ( "time" ) -var ( - // mux is the HTTP request multiplexer used with the test server. - mux *http.ServeMux - - // client is the GitHub client being tested. - client *Client - - // server is a test HTTP server used to provide mock API responses. - server *httptest.Server +const ( + // baseURLPath is a non-empty Client.BaseURL path to use during tests, + // to ensure relative URLs are used for all endpoints. See issue #752. + baseURLPath = "/api-v3" ) // setup sets up a test HTTP server along with a github.Client that is // configured to talk to that test server. Tests should register handlers on // mux which provide mock responses for the API method being tested. -func setup() { - // test server +func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown func()) { + // mux is the HTTP request multiplexer used with the test server. mux = http.NewServeMux() - server = httptest.NewServer(mux) - // github client configured to use test server + // We want to ensure that tests catch mistakes where the endpoint URL is + // specified as absolute rather than relative. It only makes a difference + // when there's a non-empty base URL path. So, use that. See issue #752. + apiHandler := http.NewServeMux() + apiHandler.Handle(baseURLPath+"/", http.StripPrefix(baseURLPath, mux)) + apiHandler.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + fmt.Fprintln(os.Stderr, "FAIL: Client.BaseURL path prefix is not preserved in the request URL:") + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "\t"+req.URL.String()) + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "\tDid you accidentally use an absolute endpoint URL rather than relative?") + fmt.Fprintln(os.Stderr, "\tSee https://github.com/google/go-github/issues/752 for information.") + http.Error(w, "Client.BaseURL path prefix is not preserved in the request URL.", http.StatusInternalServerError) + }) + + // server is a test HTTP server used to provide mock API responses. + server := httptest.NewServer(apiHandler) + + // client is the GitHub client being tested and is + // configured to use test server. client = NewClient(nil) - url, _ := url.Parse(server.URL + "/") + url, _ := url.Parse(server.URL + baseURLPath + "/") client.BaseURL = url client.UploadURL = url -} -// teardown closes the test HTTP server. -func teardown() { - server.Close() + return client, mux, server.URL, server.Close } // openTestFile creates a new file with the given name and content for testing. @@ -164,6 +174,41 @@ func TestNewClient(t *testing.T) { } } +func TestNewEnterpriseClient(t *testing.T) { + baseURL := "https://custom-url/" + uploadURL := "https://custom-upload-url/" + c, err := NewEnterpriseClient(baseURL, uploadURL, nil) + if err != nil { + t.Fatalf("NewEnterpriseClient returned unexpected error: %v", err) + } + + if got, want := c.BaseURL.String(), baseURL; got != want { + t.Errorf("NewClient BaseURL is %v, want %v", got, want) + } + if got, want := c.UploadURL.String(), uploadURL; got != want { + t.Errorf("NewClient UploadURL is %v, want %v", got, want) + } +} + +func TestNewEnterpriseClient_addsTrailingSlashToURLs(t *testing.T) { + baseURL := "https://custom-url" + uploadURL := "https://custom-upload-url" + formattedBaseURL := baseURL + "/" + formattedUploadURL := uploadURL + "/" + + c, err := NewEnterpriseClient(baseURL, uploadURL, nil) + if err != nil { + t.Fatalf("NewEnterpriseClient returned unexpected error: %v", err) + } + + if got, want := c.BaseURL.String(), formattedBaseURL; got != want { + t.Errorf("NewClient BaseURL is %v, want %v", got, want) + } + if got, want := c.UploadURL.String(), formattedUploadURL; got != want { + t.Errorf("NewClient UploadURL is %v, want %v", got, want) + } +} + // Ensure that length of Client.rateLimits is the same as number of fields in RateLimits struct. func TestClient_rateLimits(t *testing.T) { if got, want := len(Client{}.rateLimits), reflect.TypeOf(RateLimits{}).NumField(); got != want { @@ -201,7 +246,7 @@ func TestNewRequest_invalidJSON(t *testing.T) { type T struct { A map[interface{}]interface{} } - _, err := c.NewRequest("GET", "/", &T{}) + _, err := c.NewRequest("GET", ".", &T{}) if err == nil { t.Error("Expected error to be returned.") @@ -222,7 +267,7 @@ func TestNewRequest_badURL(t *testing.T) { func TestNewRequest_emptyUserAgent(t *testing.T) { c := NewClient(nil) c.UserAgent = "" - req, err := c.NewRequest("GET", "/", nil) + req, err := c.NewRequest("GET", ".", nil) if err != nil { t.Fatalf("NewRequest returned unexpected error: %v", err) } @@ -239,7 +284,7 @@ func TestNewRequest_emptyUserAgent(t *testing.T) { // subtle errors. func TestNewRequest_emptyBody(t *testing.T) { c := NewClient(nil) - req, err := c.NewRequest("GET", "/", nil) + req, err := c.NewRequest("GET", ".", nil) if err != nil { t.Fatalf("NewRequest returned unexpected error: %v", err) } @@ -360,7 +405,7 @@ func TestResponse_populatePageValues_invalid(t *testing.T) { } func TestDo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() type foo struct { @@ -368,13 +413,11 @@ func TestDo(t *testing.T) { } mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if m := "GET"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "GET") fmt.Fprint(w, `{"A":"a"}`) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) body := new(foo) client.Do(context.Background(), req, body) @@ -385,18 +428,21 @@ func TestDo(t *testing.T) { } func TestDo_httpError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Error(w, "Bad Request", 400) }) - req, _ := client.NewRequest("GET", "/", nil) - _, err := client.Do(context.Background(), req, nil) + req, _ := client.NewRequest("GET", ".", nil) + resp, err := client.Do(context.Background(), req, nil) if err == nil { - t.Error("Expected HTTP 400 error.") + t.Fatal("Expected HTTP 400 error, got no error.") + } + if resp.StatusCode != 400 { + t.Errorf("Expected HTTP 400 error, got %d status code.", resp.StatusCode) } } @@ -404,14 +450,14 @@ func TestDo_httpError(t *testing.T) { // function. A redirect loop is pretty unlikely to occur within the GitHub // API, but does allow us to exercise the right code path. func TestDo_redirectLoop(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/", http.StatusFound) + http.Redirect(w, r, baseURLPath, http.StatusFound) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) _, err := client.Do(context.Background(), req, nil) if err == nil { @@ -431,7 +477,7 @@ func TestDo_sanitizeURL(t *testing.T) { } unauthedClient := NewClient(tp.Client()) unauthedClient.BaseURL = &url.URL{Scheme: "http", Host: "127.0.0.1:0", Path: "/"} // Use port 0 on purpose to trigger a dial TCP error, expect to get "dial tcp 127.0.0.1:0: connect: can't assign requested address". - req, err := unauthedClient.NewRequest("GET", "/", nil) + req, err := unauthedClient.NewRequest("GET", ".", nil) if err != nil { t.Fatalf("NewRequest returned unexpected error: %v", err) } @@ -445,7 +491,7 @@ func TestDo_sanitizeURL(t *testing.T) { } func TestDo_rateLimit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -454,7 +500,7 @@ func TestDo_rateLimit(t *testing.T) { w.Header().Set(headerRateReset, "1372700873") }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) resp, err := client.Do(context.Background(), req, nil) if err != nil { t.Errorf("Do returned unexpected error: %v", err) @@ -465,7 +511,7 @@ func TestDo_rateLimit(t *testing.T) { if got, want := resp.Rate.Remaining, 59; got != want { t.Errorf("Client rate remaining = %v, want %v", got, want) } - reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC) + reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) if resp.Rate.Reset.UTC() != reset { t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset) } @@ -473,7 +519,7 @@ func TestDo_rateLimit(t *testing.T) { // ensure rate limit is still parsed, even for error responses func TestDo_rateLimit_errorResponse(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -483,7 +529,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { http.Error(w, "Bad Request", 400) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) resp, err := client.Do(context.Background(), req, nil) if err == nil { t.Error("Expected error to be returned.") @@ -497,7 +543,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { if got, want := resp.Rate.Remaining, 59; got != want { t.Errorf("Client rate remaining = %v, want %v", got, want) } - reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC) + reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) if resp.Rate.Reset.UTC() != reset { t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset) } @@ -505,7 +551,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { // Ensure *RateLimitError is returned when API rate limit is exceeded. func TestDo_rateLimit_rateLimitError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -520,7 +566,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { }`) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) _, err := client.Do(context.Background(), req, nil) if err == nil { @@ -536,7 +582,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { if got, want := rateLimitErr.Rate.Remaining, 0; got != want { t.Errorf("rateLimitErr rate remaining = %v, want %v", got, want) } - reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC) + reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) if rateLimitErr.Rate.Reset.UTC() != reset { t.Errorf("rateLimitErr rate reset = %v, want %v", rateLimitErr.Rate.Reset.UTC(), reset) } @@ -544,7 +590,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { // Ensure a network call is not made when it's known that API rate limit is still exceeded. func TestDo_rateLimit_noNetworkCall(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() reset := time.Now().UTC().Add(time.Minute).Round(time.Second) // Rate reset is a minute from now, with 1 second precision. @@ -567,11 +613,11 @@ func TestDo_rateLimit_noNetworkCall(t *testing.T) { }) // First request is made, and it makes the client aware of rate reset time being in the future. - req, _ := client.NewRequest("GET", "/first", nil) + req, _ := client.NewRequest("GET", "first", nil) client.Do(context.Background(), req, nil) // Second request should not cause a network call to be made, since client can predict a rate limit error. - req, _ = client.NewRequest("GET", "/second", nil) + req, _ = client.NewRequest("GET", "second", nil) _, err := client.Do(context.Background(), req, nil) if madeNetworkCall { @@ -599,7 +645,7 @@ func TestDo_rateLimit_noNetworkCall(t *testing.T) { // Ensure *AbuseRateLimitError is returned when the response indicates that // the client has triggered an abuse detection mechanism. func TestDo_rateLimit_abuseRateLimitError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -609,11 +655,45 @@ func TestDo_rateLimit_abuseRateLimitError(t *testing.T) { // there is no "Retry-After" header. fmt.Fprintln(w, `{ "message": "You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.", - "documentation_url": "https://developer.github.com/v3#abuse-rate-limits" + "documentation_url": "https://developer.github.com/v3/#abuse-rate-limits" }`) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) + _, err := client.Do(context.Background(), req, nil) + + if err == nil { + t.Error("Expected error to be returned.") + } + abuseRateLimitErr, ok := err.(*AbuseRateLimitError) + if !ok { + t.Fatalf("Expected a *AbuseRateLimitError error; got %#v.", err) + } + if got, want := abuseRateLimitErr.RetryAfter, (*time.Duration)(nil); got != want { + t.Errorf("abuseRateLimitErr RetryAfter = %v, want %v", got, want) + } +} + +// Ensure *AbuseRateLimitError is returned when the response indicates that +// the client has triggered an abuse detection mechanism on GitHub Enterprise. +func TestDo_rateLimit_abuseRateLimitErrorEnterprise(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.WriteHeader(http.StatusForbidden) + // When the abuse rate limit error is of the "temporarily blocked from content creation" type, + // there is no "Retry-After" header. + // This response returns a documentation url like the one returned for GitHub Enterprise, this + // url changes between versions but follows roughly the same format. + fmt.Fprintln(w, `{ + "message": "You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.", + "documentation_url": "https://developer.github.com/enterprise/2.12/v3/#abuse-rate-limits" +}`) + }) + + req, _ := client.NewRequest("GET", ".", nil) _, err := client.Do(context.Background(), req, nil) if err == nil { @@ -630,7 +710,7 @@ func TestDo_rateLimit_abuseRateLimitError(t *testing.T) { // Ensure *AbuseRateLimitError.RetryAfter is parsed correctly. func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -639,11 +719,11 @@ func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) { w.WriteHeader(http.StatusForbidden) fmt.Fprintln(w, `{ "message": "You have triggered an abuse detection mechanism ...", - "documentation_url": "https://developer.github.com/v3#abuse-rate-limits" + "documentation_url": "https://developer.github.com/v3/#abuse-rate-limits" }`) }) - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) _, err := client.Do(context.Background(), req, nil) if err == nil { @@ -662,7 +742,7 @@ func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) { } func TestDo_noContent(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -671,7 +751,7 @@ func TestDo_noContent(t *testing.T) { var body json.RawMessage - req, _ := client.NewRequest("GET", "/", nil) + req, _ := client.NewRequest("GET", ".", nil) _, err := client.Do(context.Background(), req, &body) if err != nil { t.Fatalf("Do returned unexpected error: %v", err) @@ -720,7 +800,7 @@ func TestCheckResponse(t *testing.T) { CreatedAt *Timestamp `json:"created_at,omitempty"` }{ Reason: "dmca", - CreatedAt: &Timestamp{time.Date(2016, 3, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, }, } if !reflect.DeepEqual(err, want) { @@ -801,13 +881,11 @@ func TestError_Error(t *testing.T) { } func TestRateLimits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, r *http.Request) { - if m := "GET"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } + testMethod(t, r, "GET") fmt.Fprint(w, `{"resources":{ "core": {"limit":2,"remaining":1,"reset":1372700873}, "search": {"limit":3,"remaining":2,"reset":1372700874} @@ -823,12 +901,12 @@ func TestRateLimits(t *testing.T) { Core: &Rate{ Limit: 2, Remaining: 1, - Reset: Timestamp{time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC).Local()}, + Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC).Local()}, }, Search: &Rate{ Limit: 3, Remaining: 2, - Reset: Timestamp{time.Date(2013, 7, 1, 17, 47, 54, 0, time.UTC).Local()}, + Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 54, 0, time.UTC).Local()}, }, } if !reflect.DeepEqual(rate, want) { @@ -844,7 +922,7 @@ func TestRateLimits(t *testing.T) { } func TestUnauthenticatedRateLimitedTransport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -864,7 +942,7 @@ func TestUnauthenticatedRateLimitedTransport(t *testing.T) { } unauthedClient := NewClient(tp.Client()) unauthedClient.BaseURL = client.BaseURL - req, _ := unauthedClient.NewRequest("GET", "/", nil) + req, _ := unauthedClient.NewRequest("GET", ".", nil) unauthedClient.Do(context.Background(), req, nil) } @@ -910,7 +988,7 @@ func TestUnauthenticatedRateLimitedTransport_transport(t *testing.T) { } func TestBasicAuthTransport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() username, password, otp := "u", "p", "123456" @@ -938,7 +1016,7 @@ func TestBasicAuthTransport(t *testing.T) { } basicAuthClient := NewClient(tp.Client()) basicAuthClient.BaseURL = client.BaseURL - req, _ := basicAuthClient.NewRequest("GET", "/", nil) + req, _ := basicAuthClient.NewRequest("GET", ".", nil) basicAuthClient.Do(context.Background(), req, nil) } @@ -994,3 +1072,12 @@ func TestFormatRateReset(t *testing.T) { t.Errorf("Format is wrong. got: %v, want: %v", got, want) } } + +func TestNestedStructAccessorNoPanic(t *testing.T) { + issue := &Issue{User: nil} + got := issue.GetUser().GetPlan().GetName() + want := "" + if got != want { + t.Errorf("Issues.Get.GetUser().GetPlan().GetName() returned %+v, want %+v", got, want) + } +} diff --git a/vendor/github.com/google/go-github/github/gitignore_test.go b/vendor/github.com/google/go-github/github/gitignore_test.go index e5a62643b..cdb82237c 100644 --- a/vendor/github.com/google/go-github/github/gitignore_test.go +++ b/vendor/github.com/google/go-github/github/gitignore_test.go @@ -14,7 +14,7 @@ import ( ) func TestGitignoresService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gitignore/templates", func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +34,7 @@ func TestGitignoresService_List(t *testing.T) { } func TestGitignoresService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gitignore/templates/name", func(w http.ResponseWriter, r *http.Request) { @@ -54,6 +54,9 @@ func TestGitignoresService_Get(t *testing.T) { } func TestGitignoresService_Get_invalidTemplate(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gitignores.Get(context.Background(), "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/issues.go b/vendor/github.com/google/go-github/github/issues.go index 9b7a9d687..1e0991ce4 100644 --- a/vendor/github.com/google/go-github/github/issues.go +++ b/vendor/github.com/google/go-github/github/issues.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "strings" "time" ) @@ -25,7 +26,7 @@ type IssuesService service // this is an issue, and if PullRequestLinks is not nil, this is a pull request. // The IsPullRequest helper method can be used to check that. type Issue struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Number *int `json:"number,omitempty"` State *string `json:"state,omitempty"` Locked *bool `json:"locked,omitempty"` @@ -50,10 +51,15 @@ type Issue struct { Repository *Repository `json:"repository,omitempty"` Reactions *Reactions `json:"reactions,omitempty"` Assignees []*User `json:"assignees,omitempty"` + NodeID *string `json:"node_id,omitempty"` // TextMatches is only populated from search results that request text matches // See: search.go and https://developer.github.com/v3/search/#text-match-metadata TextMatches []TextMatch `json:"text_matches,omitempty"` + + // ActiveLockReason is populated only when LockReason is provided while locking the issue. + // Possible values are: "off-topic", "too heated", "resolved", and "spam". + ActiveLockReason *string `json:"active_lock_reason,omitempty"` } func (i Issue) String() string { @@ -153,8 +159,9 @@ func (s *IssuesService) listIssues(ctx context.Context, u string, opt *IssueList return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeReactionsPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) var issues []*Issue resp, err := s.client.Do(ctx, req, &issues) @@ -220,8 +227,9 @@ func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo strin return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeReactionsPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeIntegrationPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) var issues []*Issue resp, err := s.client.Do(ctx, req, &issues) @@ -242,8 +250,9 @@ func (s *IssuesService) Get(ctx context.Context, owner string, repo string, numb return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeReactionsPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) issue := new(Issue) resp, err := s.client.Do(ctx, req, issue) @@ -264,6 +273,9 @@ func (s *IssuesService) Create(ctx context.Context, owner string, repo string, i return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + i := new(Issue) resp, err := s.client.Do(ctx, req, i) if err != nil { @@ -283,6 +295,9 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + i := new(Issue) resp, err := s.client.Do(ctx, req, i) if err != nil { @@ -292,16 +307,29 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num return i, resp, nil } +// LockIssueOptions specifies the optional parameters to the +// IssuesService.Lock method. +type LockIssueOptions struct { + // LockReason specifies the reason to lock this issue. + // Providing a lock reason can help make it clearer to contributors why an issue + // was locked. Possible values are: "off-topic", "too heated", "resolved", and "spam". + LockReason string `json:"lock_reason,omitempty"` +} + // Lock an issue's conversation. // // GitHub API docs: https://developer.github.com/v3/issues/#lock-an-issue -func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int) (*Response, error) { +func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int, opt *LockIssueOptions) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number) - req, err := s.client.NewRequest("PUT", u, nil) + req, err := s.client.NewRequest("PUT", u, opt) if err != nil { return nil, err } + if opt != nil { + req.Header.Set("Accept", mediaTypeLockReasonPreview) + } + return s.client.Do(ctx, req, nil) } diff --git a/vendor/github.com/google/go-github/github/issues_assignees_test.go b/vendor/github.com/google/go-github/github/issues_assignees_test.go index d88a7888a..bb2bf4ff0 100644 --- a/vendor/github.com/google/go-github/github/issues_assignees_test.go +++ b/vendor/github.com/google/go-github/github/issues_assignees_test.go @@ -15,7 +15,7 @@ import ( ) func TestIssuesService_ListAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { @@ -30,19 +30,22 @@ func TestIssuesService_ListAssignees(t *testing.T) { t.Errorf("Issues.ListAssignees returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(assignees, want) { t.Errorf("Issues.ListAssignees returned %+v, want %+v", assignees, want) } } func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListAssignees(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_IsAssignee_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -59,7 +62,7 @@ func TestIssuesService_IsAssignee_true(t *testing.T) { } func TestIssuesService_IsAssignee_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -77,7 +80,7 @@ func TestIssuesService_IsAssignee_false(t *testing.T) { } func TestIssuesService_IsAssignee_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -95,12 +98,15 @@ func TestIssuesService_IsAssignee_error(t *testing.T) { } func TestIssuesService_IsAssignee_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.IsAssignee(context.Background(), "%", "r", "u") testURLParseError(t, err) } func TestIssuesService_AddAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/assignees", func(w http.ResponseWriter, r *http.Request) { @@ -129,7 +135,7 @@ func TestIssuesService_AddAssignees(t *testing.T) { } func TestIssuesService_RemoveAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/assignees", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/issues_comments.go b/vendor/github.com/google/go-github/github/issues_comments.go index fd72657cd..ab68afe2f 100644 --- a/vendor/github.com/google/go-github/github/issues_comments.go +++ b/vendor/github.com/google/go-github/github/issues_comments.go @@ -13,15 +13,19 @@ import ( // IssueComment represents a comment left on an issue. type IssueComment struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` Body *string `json:"body,omitempty"` User *User `json:"user,omitempty"` Reactions *Reactions `json:"reactions,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - IssueURL *string `json:"issue_url,omitempty"` + // AuthorAssociation is the comment author's relationship to the issue's repository. + // Possible values are "COLLABORATOR", "CONTRIBUTOR", "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR", "MEMBER", "OWNER", or "NONE". + AuthorAssociation *string `json:"author_association,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + IssueURL *string `json:"issue_url,omitempty"` } func (i IssueComment) String() string { @@ -79,8 +83,8 @@ func (s *IssuesService) ListComments(ctx context.Context, owner string, repo str // GetComment fetches the specified issue comment. // // GitHub API docs: https://developer.github.com/v3/issues/comments/#get-a-single-comment -func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, id int) (*IssueComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) +func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -118,10 +122,11 @@ func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo st } // EditComment updates an issue comment. +// A non-nil comment.Body must be provided. Other comment fields should be left nil. // // GitHub API docs: https://developer.github.com/v3/issues/comments/#edit-a-comment -func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, id int, comment *IssueComment) (*IssueComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) +func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("PATCH", u, comment) if err != nil { return nil, nil, err @@ -138,8 +143,8 @@ func (s *IssuesService) EditComment(ctx context.Context, owner string, repo stri // DeleteComment deletes an issue comment. // // GitHub API docs: https://developer.github.com/v3/issues/comments/#delete-a-comment -func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, id int) (*Response, error) { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) +func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/vendor/github.com/google/go-github/github/issues_comments_test.go b/vendor/github.com/google/go-github/github/issues_comments_test.go index 78c486362..6911a7985 100644 --- a/vendor/github.com/google/go-github/github/issues_comments_test.go +++ b/vendor/github.com/google/go-github/github/issues_comments_test.go @@ -16,7 +16,7 @@ import ( ) func TestIssuesService_ListComments_allIssues(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments", func(w http.ResponseWriter, r *http.Request) { @@ -42,14 +42,14 @@ func TestIssuesService_ListComments_allIssues(t *testing.T) { t.Errorf("Issues.ListComments returned error: %v", err) } - want := []*IssueComment{{ID: Int(1)}} + want := []*IssueComment{{ID: Int64(1)}} if !reflect.DeepEqual(comments, want) { t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) } } func TestIssuesService_ListComments_specificIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -63,19 +63,22 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) { t.Errorf("Issues.ListComments returned error: %v", err) } - want := []*IssueComment{{ID: Int(1)}} + want := []*IssueComment{{ID: Int64(1)}} if !reflect.DeepEqual(comments, want) { t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) } } func TestIssuesService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListComments(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -89,19 +92,22 @@ func TestIssuesService_GetComment(t *testing.T) { t.Errorf("Issues.GetComment returned error: %v", err) } - want := &IssueComment{ID: Int(1)} + want := &IssueComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Issues.GetComment returned %+v, want %+v", comment, want) } } func TestIssuesService_GetComment_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueComment{Body: String("b")} @@ -123,19 +129,22 @@ func TestIssuesService_CreateComment(t *testing.T) { t.Errorf("Issues.CreateComment returned error: %v", err) } - want := &IssueComment{ID: Int(1)} + want := &IssueComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Issues.CreateComment returned %+v, want %+v", comment, want) } } func TestIssuesService_CreateComment_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueComment{Body: String("b")} @@ -157,19 +166,22 @@ func TestIssuesService_EditComment(t *testing.T) { t.Errorf("Issues.EditComment returned error: %v", err) } - want := &IssueComment{ID: Int(1)} + want := &IssueComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Issues.EditComment returned %+v, want %+v", comment, want) } } func TestIssuesService_EditComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +195,9 @@ func TestIssuesService_DeleteComment(t *testing.T) { } func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/issues_events.go b/vendor/github.com/google/go-github/github/issues_events.go index 93e5d66fb..6a43f1062 100644 --- a/vendor/github.com/google/go-github/github/issues_events.go +++ b/vendor/github.com/google/go-github/github/issues_events.go @@ -8,12 +8,13 @@ package github import ( "context" "fmt" + "strings" "time" ) // IssueEvent represents an event that occurred around an Issue or Pull Request. type IssueEvent struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` // The User that generated this event. @@ -34,9 +35,13 @@ type IssueEvent struct { // The Actor committed to master a commit mentioning the issue in its commit message. // CommitID holds the SHA1 of the commit. // - // reopened, locked, unlocked + // reopened, unlocked // The Actor did that to the issue. // + // locked + // The Actor locked the issue. + // LockReason holds the reason of locking the issue (if provided while locking). + // // renamed // The Actor changed the issue title from Rename.From to Rename.To. // @@ -64,12 +69,14 @@ type IssueEvent struct { Issue *Issue `json:"issue,omitempty"` // Only present on certain events; see above. - Assignee *User `json:"assignee,omitempty"` - Assigner *User `json:"assigner,omitempty"` - CommitID *string `json:"commit_id,omitempty"` - Milestone *Milestone `json:"milestone,omitempty"` - Label *Label `json:"label,omitempty"` - Rename *Rename `json:"rename,omitempty"` + Assignee *User `json:"assignee,omitempty"` + Assigner *User `json:"assigner,omitempty"` + CommitID *string `json:"commit_id,omitempty"` + Milestone *Milestone `json:"milestone,omitempty"` + Label *Label `json:"label,omitempty"` + Rename *Rename `json:"rename,omitempty"` + LockReason *string `json:"lock_reason,omitempty"` + ProjectCard *ProjectCard `json:"project_card,omitempty"` } // ListIssueEvents lists events for the specified issue. @@ -87,6 +94,9 @@ func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, return nil, nil, err } + acceptHeaders := []string{mediaTypeLockReasonPreview, mediaTypeProjectCardDetailsPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) + var events []*IssueEvent resp, err := s.client.Do(ctx, req, &events) if err != nil { @@ -123,7 +133,7 @@ func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo st // GetEvent returns the specified issue event. // // GitHub API docs: https://developer.github.com/v3/issues/events/#get-a-single-event -func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int) (*IssueEvent, *Response, error) { +func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) diff --git a/vendor/github.com/google/go-github/github/issues_events_test.go b/vendor/github.com/google/go-github/github/issues_events_test.go index d85b6223e..fe21ecbe8 100644 --- a/vendor/github.com/google/go-github/github/issues_events_test.go +++ b/vendor/github.com/google/go-github/github/issues_events_test.go @@ -14,7 +14,7 @@ import ( ) func TestIssuesService_ListIssueEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/events", func(w http.ResponseWriter, r *http.Request) { @@ -32,14 +32,14 @@ func TestIssuesService_ListIssueEvents(t *testing.T) { t.Errorf("Issues.ListIssueEvents returned error: %v", err) } - want := []*IssueEvent{{ID: Int(1)}} + want := []*IssueEvent{{ID: Int64(1)}} if !reflect.DeepEqual(events, want) { t.Errorf("Issues.ListIssueEvents returned %+v, want %+v", events, want) } } func TestIssuesService_ListRepositoryEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events", func(w http.ResponseWriter, r *http.Request) { @@ -57,14 +57,14 @@ func TestIssuesService_ListRepositoryEvents(t *testing.T) { t.Errorf("Issues.ListRepositoryEvents returned error: %v", err) } - want := []*IssueEvent{{ID: Int(1)}} + want := []*IssueEvent{{ID: Int64(1)}} if !reflect.DeepEqual(events, want) { t.Errorf("Issues.ListRepositoryEvents returned %+v, want %+v", events, want) } } func TestIssuesService_GetEvent(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events/1", func(w http.ResponseWriter, r *http.Request) { @@ -77,7 +77,7 @@ func TestIssuesService_GetEvent(t *testing.T) { t.Errorf("Issues.GetEvent returned error: %v", err) } - want := &IssueEvent{ID: Int(1)} + want := &IssueEvent{ID: Int64(1)} if !reflect.DeepEqual(event, want) { t.Errorf("Issues.GetEvent returned %+v, want %+v", event, want) } diff --git a/vendor/github.com/google/go-github/github/issues_labels.go b/vendor/github.com/google/go-github/github/issues_labels.go index b0e34c40f..adcbe0683 100644 --- a/vendor/github.com/google/go-github/github/issues_labels.go +++ b/vendor/github.com/google/go-github/github/issues_labels.go @@ -12,10 +12,13 @@ import ( // Label represents a GitHub label on an Issue type Label struct { - ID *int `json:"id,omitempty"` - URL *string `json:"url,omitempty"` - Name *string `json:"name,omitempty"` - Color *string `json:"color,omitempty"` + ID *int64 `json:"id,omitempty"` + URL *string `json:"url,omitempty"` + Name *string `json:"name,omitempty"` + Color *string `json:"color,omitempty"` + Description *string `json:"description,omitempty"` + Default *bool `json:"default,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (l Label) String() string { @@ -37,6 +40,9 @@ func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo strin return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + var labels []*Label resp, err := s.client.Do(ctx, req, &labels) if err != nil { @@ -56,6 +62,9 @@ func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string, return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + label := new(Label) resp, err := s.client.Do(ctx, req, label) if err != nil { @@ -75,6 +84,9 @@ func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo stri return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + l := new(Label) resp, err := s.client.Do(ctx, req, l) if err != nil { @@ -94,6 +106,9 @@ func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + l := new(Label) resp, err := s.client.Do(ctx, req, l) if err != nil { @@ -130,6 +145,9 @@ func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, rep return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + var labels []*Label resp, err := s.client.Do(ctx, req, &labels) if err != nil { @@ -149,6 +167,9 @@ func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + var l []*Label resp, err := s.client.Do(ctx, req, &l) if err != nil { @@ -167,6 +188,10 @@ func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, r if err != nil { return nil, err } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + return s.client.Do(ctx, req, nil) } @@ -180,6 +205,9 @@ func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string, return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + var l []*Label resp, err := s.client.Do(ctx, req, &l) if err != nil { @@ -198,6 +226,10 @@ func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string, if err != nil { return nil, err } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + return s.client.Do(ctx, req, nil) } @@ -216,6 +248,9 @@ func (s *IssuesService) ListLabelsForMilestone(ctx context.Context, owner string return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + var labels []*Label resp, err := s.client.Do(ctx, req, &labels) if err != nil { diff --git a/vendor/github.com/google/go-github/github/issues_labels_test.go b/vendor/github.com/google/go-github/github/issues_labels_test.go index 5380427a1..6437d8800 100644 --- a/vendor/github.com/google/go-github/github/issues_labels_test.go +++ b/vendor/github.com/google/go-github/github/issues_labels_test.go @@ -15,11 +15,12 @@ import ( ) func TestIssuesService_ListLabels(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`) }) @@ -37,17 +38,21 @@ func TestIssuesService_ListLabels(t *testing.T) { } func TestIssuesService_ListLabels_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabels(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_GetLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels/n", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"url":"u", "name": "n", "color": "c"}`) + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) + fmt.Fprint(w, `{"url":"u", "name": "n", "color": "c", "description": "d"}`) }) label, _, err := client.Issues.GetLabel(context.Background(), "o", "r", "n") @@ -55,19 +60,22 @@ func TestIssuesService_GetLabel(t *testing.T) { t.Errorf("Issues.GetLabel returned error: %v", err) } - want := &Label{URL: String("u"), Name: String("n"), Color: String("c")} + want := &Label{URL: String("u"), Name: String("n"), Color: String("c"), Description: String("d")} if !reflect.DeepEqual(label, want) { t.Errorf("Issues.GetLabel returned %+v, want %+v", label, want) } } func TestIssuesService_GetLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetLabel(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestIssuesService_CreateLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Label{Name: String("n")} @@ -77,6 +85,7 @@ func TestIssuesService_CreateLabel(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -96,12 +105,15 @@ func TestIssuesService_CreateLabel(t *testing.T) { } func TestIssuesService_CreateLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateLabel(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_EditLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Label{Name: String("z")} @@ -111,6 +123,7 @@ func TestIssuesService_EditLabel(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -130,12 +143,15 @@ func TestIssuesService_EditLabel(t *testing.T) { } func TestIssuesService_EditLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditLabel(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_DeleteLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels/n", func(w http.ResponseWriter, r *http.Request) { @@ -149,16 +165,20 @@ func TestIssuesService_DeleteLabel(t *testing.T) { } func TestIssuesService_DeleteLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteLabel(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestIssuesService_ListLabelsByIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"name":"a","id":1},{"name":"b","id":2}]`) }) @@ -170,8 +190,8 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) { } want := []*Label{ - {Name: String("a"), ID: Int(1)}, - {Name: String("b"), ID: Int(2)}, + {Name: String("a"), ID: Int64(1)}, + {Name: String("b"), ID: Int64(2)}, } if !reflect.DeepEqual(labels, want) { t.Errorf("Issues.ListLabelsByIssue returned %+v, want %+v", labels, want) @@ -179,12 +199,15 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) { } func TestIssuesService_ListLabelsByIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabelsByIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_AddLabelsToIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"a", "b"} @@ -194,6 +217,7 @@ func TestIssuesService_AddLabelsToIssue(t *testing.T) { json.NewDecoder(r.Body).Decode(&v) testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -213,15 +237,19 @@ func TestIssuesService_AddLabelsToIssue(t *testing.T) { } func TestIssuesService_AddLabelsToIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.AddLabelsToIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_RemoveLabelForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels/l", func(w http.ResponseWriter, r *http.Request) { + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) testMethod(t, r, "DELETE") }) @@ -232,12 +260,15 @@ func TestIssuesService_RemoveLabelForIssue(t *testing.T) { } func TestIssuesService_RemoveLabelForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.RemoveLabelForIssue(context.Background(), "%", "%", 1, "%") testURLParseError(t, err) } func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"a", "b"} @@ -247,6 +278,7 @@ func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) { json.NewDecoder(r.Body).Decode(&v) testMethod(t, r, "PUT") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -266,16 +298,20 @@ func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) { } func TestIssuesService_ReplaceLabelsForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ReplaceLabelsForIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_RemoveLabelsForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) }) _, err := client.Issues.RemoveLabelsForIssue(context.Background(), "o", "r", 1) @@ -285,16 +321,20 @@ func TestIssuesService_RemoveLabelsForIssue(t *testing.T) { } func TestIssuesService_RemoveLabelsForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.RemoveLabelsForIssue(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestIssuesService_ListLabelsForMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1/labels", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`) }) @@ -312,6 +352,9 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) { } func TestIssuesService_ListLabelsForMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabelsForMilestone(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/issues_milestones.go b/vendor/github.com/google/go-github/github/issues_milestones.go index e6e882d14..ffe9aae14 100644 --- a/vendor/github.com/google/go-github/github/issues_milestones.go +++ b/vendor/github.com/google/go-github/github/issues_milestones.go @@ -16,7 +16,7 @@ type Milestone struct { URL *string `json:"url,omitempty"` HTMLURL *string `json:"html_url,omitempty"` LabelsURL *string `json:"labels_url,omitempty"` - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Number *int `json:"number,omitempty"` State *string `json:"state,omitempty"` Title *string `json:"title,omitempty"` @@ -28,6 +28,7 @@ type Milestone struct { UpdatedAt *time.Time `json:"updated_at,omitempty"` ClosedAt *time.Time `json:"closed_at,omitempty"` DueOn *time.Time `json:"due_on,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (m Milestone) String() string { diff --git a/vendor/github.com/google/go-github/github/issues_milestones_test.go b/vendor/github.com/google/go-github/github/issues_milestones_test.go index befa1b487..019f00a8b 100644 --- a/vendor/github.com/google/go-github/github/issues_milestones_test.go +++ b/vendor/github.com/google/go-github/github/issues_milestones_test.go @@ -15,7 +15,7 @@ import ( ) func TestIssuesService_ListMilestones(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones", func(w http.ResponseWriter, r *http.Request) { @@ -42,12 +42,15 @@ func TestIssuesService_ListMilestones(t *testing.T) { } func TestIssuesService_ListMilestones_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListMilestones(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_GetMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) { @@ -67,12 +70,15 @@ func TestIssuesService_GetMilestone(t *testing.T) { } func TestIssuesService_GetMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetMilestone(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_CreateMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Milestone{Title: String("t")} @@ -101,12 +107,15 @@ func TestIssuesService_CreateMilestone(t *testing.T) { } func TestIssuesService_CreateMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateMilestone(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_EditMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Milestone{Title: String("t")} @@ -135,12 +144,15 @@ func TestIssuesService_EditMilestone(t *testing.T) { } func TestIssuesService_EditMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditMilestone(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_DeleteMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) { @@ -154,6 +166,9 @@ func TestIssuesService_DeleteMilestone(t *testing.T) { } func TestIssuesService_DeleteMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteMilestone(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/issues_test.go b/vendor/github.com/google/go-github/github/issues_test.go index da60740fb..22190a028 100644 --- a/vendor/github.com/google/go-github/github/issues_test.go +++ b/vendor/github.com/google/go-github/github/issues_test.go @@ -11,17 +11,19 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" "time" ) func TestIssuesService_List_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/issues", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeReactionsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) testFormValues(t, r, values{ "filter": "all", "state": "closed", @@ -52,12 +54,13 @@ func TestIssuesService_List_all(t *testing.T) { } func TestIssuesService_List_owned(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/user/issues", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeReactionsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) fmt.Fprint(w, `[{"number":1}]`) }) @@ -73,12 +76,13 @@ func TestIssuesService_List_owned(t *testing.T) { } func TestIssuesService_ListByOrg(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/orgs/o/issues", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeReactionsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) fmt.Fprint(w, `[{"number":1}]`) }) @@ -94,17 +98,21 @@ func TestIssuesService_ListByOrg(t *testing.T) { } func TestIssuesService_ListByOrg_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListByOrg(context.Background(), "%", nil) testURLParseError(t, err) } func TestIssuesService_ListByRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeIntegrationPreview} mux.HandleFunc("/repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeReactionsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) testFormValues(t, r, values{ "milestone": "*", "state": "closed", @@ -136,17 +144,21 @@ func TestIssuesService_ListByRepo(t *testing.T) { } func TestIssuesService_ListByRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListByRepo(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/repos/o/r/issues/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeReactionsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) fmt.Fprint(w, `{"number":1, "labels": [{"url": "u", "name": "n", "color": "c"}]}`) }) @@ -169,12 +181,15 @@ func TestIssuesService_Get(t *testing.T) { } func TestIssuesService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Get(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueRequest{ @@ -189,6 +204,7 @@ func TestIssuesService_Create(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -208,12 +224,15 @@ func TestIssuesService_Create(t *testing.T) { } func TestIssuesService_Create_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Create(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueRequest{Title: String("t")} @@ -223,6 +242,7 @@ func TestIssuesService_Edit(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -242,12 +262,15 @@ func TestIssuesService_Edit(t *testing.T) { } func TestIssuesService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Edit(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_Lock(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { @@ -256,13 +279,30 @@ func TestIssuesService_Lock(t *testing.T) { w.WriteHeader(http.StatusNoContent) }) - if _, err := client.Issues.Lock(context.Background(), "o", "r", 1); err != nil { + if _, err := client.Issues.Lock(context.Background(), "o", "r", 1, nil); err != nil { + t.Errorf("Issues.Lock returned error: %v", err) + } +} + +func TestIssuesService_LockWithReason(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Accept", mediaTypeLockReasonPreview) + w.WriteHeader(http.StatusNoContent) + }) + + opt := &LockIssueOptions{LockReason: "off-topic"} + + if _, err := client.Issues.Lock(context.Background(), "o", "r", 1, opt); err != nil { t.Errorf("Issues.Lock returned error: %v", err) } } func TestIssuesService_Unlock(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/issues_timeline.go b/vendor/github.com/google/go-github/github/issues_timeline.go index bc0b10899..9cfda8320 100644 --- a/vendor/github.com/google/go-github/github/issues_timeline.go +++ b/vendor/github.com/google/go-github/github/issues_timeline.go @@ -16,7 +16,7 @@ import ( // It is similar to an IssueEvent but may contain more information. // GitHub API docs: https://developer.github.com/v3/issues/timeline/ type Timeline struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` CommitURL *string `json:"commit_url,omitempty"` @@ -120,7 +120,7 @@ type Timeline struct { // Source represents a reference's source. type Source struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` Actor *User `json:"actor,omitempty"` } diff --git a/vendor/github.com/google/go-github/github/issues_timeline_test.go b/vendor/github.com/google/go-github/github/issues_timeline_test.go index 2fd22109b..93f62368c 100644 --- a/vendor/github.com/google/go-github/github/issues_timeline_test.go +++ b/vendor/github.com/google/go-github/github/issues_timeline_test.go @@ -14,7 +14,7 @@ import ( ) func TestIssuesService_ListIssueTimeline(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/timeline", func(w http.ResponseWriter, r *http.Request) { @@ -33,7 +33,7 @@ func TestIssuesService_ListIssueTimeline(t *testing.T) { t.Errorf("Issues.ListIssueTimeline returned error: %v", err) } - want := []*Timeline{{ID: Int(1)}} + want := []*Timeline{{ID: Int64(1)}} if !reflect.DeepEqual(events, want) { t.Errorf("Issues.ListIssueTimeline = %+v, want %+v", events, want) } diff --git a/vendor/github.com/google/go-github/github/licenses.go b/vendor/github.com/google/go-github/github/licenses.go index e9cd1777a..1176d3a8b 100644 --- a/vendor/github.com/google/go-github/github/licenses.go +++ b/vendor/github.com/google/go-github/github/licenses.go @@ -67,9 +67,6 @@ func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, erro return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeLicensesPreview) - var licenses []*License resp, err := s.client.Do(ctx, req, &licenses) if err != nil { @@ -90,9 +87,6 @@ func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeLicensesPreview) - license := new(License) resp, err := s.client.Do(ctx, req, license) if err != nil { diff --git a/vendor/github.com/google/go-github/github/licenses_test.go b/vendor/github.com/google/go-github/github/licenses_test.go index 5c06e6598..a71f6a4ef 100644 --- a/vendor/github.com/google/go-github/github/licenses_test.go +++ b/vendor/github.com/google/go-github/github/licenses_test.go @@ -14,12 +14,11 @@ import ( ) func TestLicensesService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/licenses", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeLicensesPreview) fmt.Fprint(w, `[{"key":"mit","name":"MIT","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}]`) }) @@ -41,12 +40,11 @@ func TestLicensesService_List(t *testing.T) { } func TestLicensesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/licenses/mit", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeLicensesPreview) fmt.Fprint(w, `{"key":"mit","name":"MIT"}`) }) @@ -62,6 +60,9 @@ func TestLicensesService_Get(t *testing.T) { } func TestLicensesService_Get_invalidTemplate(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Licenses.Get(context.Background(), "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/messages.go b/vendor/github.com/google/go-github/github/messages.go index 3a4d46440..75bc77051 100644 --- a/vendor/github.com/google/go-github/github/messages.go +++ b/vendor/github.com/google/go-github/github/messages.go @@ -41,39 +41,43 @@ const ( var ( // eventTypeMapping maps webhooks types to their corresponding go-github struct types. eventTypeMapping = map[string]string{ - "commit_comment": "CommitCommentEvent", - "create": "CreateEvent", - "delete": "DeleteEvent", - "deployment": "DeploymentEvent", - "deployment_status": "DeploymentStatusEvent", - "fork": "ForkEvent", - "gollum": "GollumEvent", - "installation": "InstallationEvent", - "installation_repositories": "InstallationRepositoriesEvent", - "issue_comment": "IssueCommentEvent", - "issues": "IssuesEvent", - "label": "LabelEvent", - "member": "MemberEvent", - "membership": "MembershipEvent", - "milestone": "MilestoneEvent", - "organization": "OrganizationEvent", - "org_block": "OrgBlockEvent", - "page_build": "PageBuildEvent", - "ping": "PingEvent", - "project": "ProjectEvent", - "project_card": "ProjectCardEvent", - "project_column": "ProjectColumnEvent", - "public": "PublicEvent", - "pull_request_review": "PullRequestReviewEvent", - "pull_request_review_comment": "PullRequestReviewCommentEvent", - "pull_request": "PullRequestEvent", - "push": "PushEvent", - "repository": "RepositoryEvent", - "release": "ReleaseEvent", - "status": "StatusEvent", - "team": "TeamEvent", - "team_add": "TeamAddEvent", - "watch": "WatchEvent", + "check_run": "CheckRunEvent", + "check_suite": "CheckSuiteEvent", + "commit_comment": "CommitCommentEvent", + "create": "CreateEvent", + "delete": "DeleteEvent", + "deployment": "DeploymentEvent", + "deployment_status": "DeploymentStatusEvent", + "fork": "ForkEvent", + "gollum": "GollumEvent", + "installation": "InstallationEvent", + "installation_repositories": "InstallationRepositoriesEvent", + "issue_comment": "IssueCommentEvent", + "issues": "IssuesEvent", + "label": "LabelEvent", + "marketplace_purchase": "MarketplacePurchaseEvent", + "member": "MemberEvent", + "membership": "MembershipEvent", + "milestone": "MilestoneEvent", + "organization": "OrganizationEvent", + "org_block": "OrgBlockEvent", + "page_build": "PageBuildEvent", + "ping": "PingEvent", + "project": "ProjectEvent", + "project_card": "ProjectCardEvent", + "project_column": "ProjectColumnEvent", + "public": "PublicEvent", + "pull_request_review": "PullRequestReviewEvent", + "pull_request_review_comment": "PullRequestReviewCommentEvent", + "pull_request": "PullRequestEvent", + "push": "PushEvent", + "repository": "RepositoryEvent", + "repository_vulnerability_alert": "RepositoryVulnerabilityAlertEvent", + "release": "ReleaseEvent", + "status": "StatusEvent", + "team": "TeamEvent", + "team_add": "TeamAddEvent", + "watch": "WatchEvent", } ) @@ -172,19 +176,19 @@ func ValidatePayload(r *http.Request, secretKey []byte) (payload []byte, err err } sig := r.Header.Get(signatureHeader) - if err := validateSignature(sig, body, secretKey); err != nil { + if err := ValidateSignature(sig, body, secretKey); err != nil { return nil, err } return payload, nil } -// validateSignature validates the signature for the given payload. +// ValidateSignature validates the signature for the given payload. // signature is the GitHub hash signature delivered in the X-Hub-Signature header. // payload is the JSON payload sent by GitHub Webhooks. // secretKey is the GitHub Webhook secret message. // // GitHub API docs: https://developer.github.com/webhooks/securing/#validating-payloads-from-github -func validateSignature(signature string, payload, secretKey []byte) error { +func ValidateSignature(signature string, payload, secretKey []byte) error { messageMAC, hashFunc, err := messageMAC(signature) if err != nil { return err diff --git a/vendor/github.com/google/go-github/github/messages_test.go b/vendor/github.com/google/go-github/github/messages_test.go index eebfa10d3..b63f1946b 100644 --- a/vendor/github.com/google/go-github/github/messages_test.go +++ b/vendor/github.com/google/go-github/github/messages_test.go @@ -161,6 +161,14 @@ func TestParseWebHook(t *testing.T) { payload interface{} messageType string }{ + { + payload: &CheckRunEvent{}, + messageType: "check_run", + }, + { + payload: &CheckSuiteEvent{}, + messageType: "check_suite", + }, { payload: &CommitCommentEvent{}, messageType: "commit_comment", @@ -210,6 +218,10 @@ func TestParseWebHook(t *testing.T) { payload: &LabelEvent{}, messageType: "label", }, + { + payload: &MarketplacePurchaseEvent{}, + messageType: "marketplace_purchase", + }, { payload: &MemberEvent{}, messageType: "member", @@ -278,6 +290,10 @@ func TestParseWebHook(t *testing.T) { payload: &RepositoryEvent{}, messageType: "repository", }, + { + payload: &RepositoryVulnerabilityAlertEvent{}, + messageType: "repository_vulnerability_alert", + }, { payload: &StatusEvent{}, messageType: "status", diff --git a/vendor/github.com/google/go-github/github/migrations.go b/vendor/github.com/google/go-github/github/migrations.go index 6793269cd..90cc1fae8 100644 --- a/vendor/github.com/google/go-github/github/migrations.go +++ b/vendor/github.com/google/go-github/github/migrations.go @@ -21,7 +21,7 @@ type MigrationService service // Migration represents a GitHub migration (archival). type Migration struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` GUID *string `json:"guid,omitempty"` // State is the current state of a migration. // Possible values are: @@ -128,7 +128,7 @@ func (s *MigrationService) ListMigrations(ctx context.Context, org string) ([]*M // id is the migration ID. // // GitHub API docs: https://developer.github.com/v3/migration/migrations/#get-the-status-of-a-migration -func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id int) (*Migration, *Response, error) { +func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id int64) (*Migration, *Response, error) { u := fmt.Sprintf("orgs/%v/migrations/%v", org, id) req, err := s.client.NewRequest("GET", u, nil) @@ -152,7 +152,7 @@ func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id i // id is the migration ID. // // GitHub API docs: https://developer.github.com/v3/migration/migrations/#download-a-migration-archive -func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, id int) (url string, err error) { +func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, id int64) (url string, err error) { u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id) req, err := s.client.NewRequest("GET", u, nil) @@ -189,7 +189,7 @@ func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, // id is the migration ID. // // GitHub API docs: https://developer.github.com/v3/migration/migrations/#delete-a-migration-archive -func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id int) (*Response, error) { +func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id int64) (*Response, error) { u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id) req, err := s.client.NewRequest("DELETE", u, nil) @@ -209,7 +209,7 @@ func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id i // is complete and you no longer need the source data. // // GitHub API docs: https://developer.github.com/v3/migration/migrations/#unlock-a-repository -func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int, repo string) (*Response, error) { +func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int64, repo string) (*Response, error) { u := fmt.Sprintf("orgs/%v/migrations/%v/repos/%v/lock", org, id, repo) req, err := s.client.NewRequest("DELETE", u, nil) diff --git a/vendor/github.com/google/go-github/github/migrations_source_import.go b/vendor/github.com/google/go-github/github/migrations_source_import.go index aa45a5a36..fd45e7800 100644 --- a/vendor/github.com/google/go-github/github/migrations_source_import.go +++ b/vendor/github.com/google/go-github/github/migrations_source_import.go @@ -117,7 +117,7 @@ func (i Import) String() string { // // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors type SourceImportAuthor struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` RemoteID *string `json:"remote_id,omitempty"` RemoteName *string `json:"remote_name,omitempty"` Email *string `json:"email,omitempty"` @@ -247,7 +247,7 @@ func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string // commits to the repository. // // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#map-a-commit-author -func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) { +func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int64, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) { u := fmt.Sprintf("repos/%v/%v/import/authors/%v", owner, repo, id) req, err := s.client.NewRequest("PATCH", u, author) if err != nil { diff --git a/vendor/github.com/google/go-github/github/migrations_source_import_test.go b/vendor/github.com/google/go-github/github/migrations_source_import_test.go index 67b98fb42..e9e9be062 100644 --- a/vendor/github.com/google/go-github/github/migrations_source_import_test.go +++ b/vendor/github.com/google/go-github/github/migrations_source_import_test.go @@ -15,7 +15,7 @@ import ( ) func TestMigrationService_StartImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{ @@ -50,7 +50,7 @@ func TestMigrationService_StartImport(t *testing.T) { } func TestMigrationService_ImportProgress(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) { @@ -70,7 +70,7 @@ func TestMigrationService_ImportProgress(t *testing.T) { } func TestMigrationService_UpdateImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{ @@ -105,7 +105,7 @@ func TestMigrationService_UpdateImport(t *testing.T) { } func TestMigrationService_CommitAuthors(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import/authors", func(w http.ResponseWriter, r *http.Request) { @@ -119,8 +119,8 @@ func TestMigrationService_CommitAuthors(t *testing.T) { t.Errorf("CommitAuthors returned error: %v", err) } want := []*SourceImportAuthor{ - {ID: Int(1), Name: String("a")}, - {ID: Int(2), Name: String("b")}, + {ID: Int64(1), Name: String("a")}, + {ID: Int64(2), Name: String("b")}, } if !reflect.DeepEqual(got, want) { t.Errorf("CommitAuthors = %+v, want %+v", got, want) @@ -128,7 +128,7 @@ func TestMigrationService_CommitAuthors(t *testing.T) { } func TestMigrationService_MapCommitAuthor(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &SourceImportAuthor{Name: String("n"), Email: String("e")} @@ -150,14 +150,14 @@ func TestMigrationService_MapCommitAuthor(t *testing.T) { if err != nil { t.Errorf("MapCommitAuthor returned error: %v", err) } - want := &SourceImportAuthor{ID: Int(1)} + want := &SourceImportAuthor{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("MapCommitAuthor = %+v, want %+v", got, want) } } func TestMigrationService_SetLFSPreference(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{UseLFS: String("opt_in")} @@ -187,7 +187,7 @@ func TestMigrationService_SetLFSPreference(t *testing.T) { } func TestMigrationService_LargeFiles(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import/large_files", func(w http.ResponseWriter, r *http.Request) { @@ -210,7 +210,7 @@ func TestMigrationService_LargeFiles(t *testing.T) { } func TestMigrationService_CancelImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/migrations_test.go b/vendor/github.com/google/go-github/github/migrations_test.go index 7e0ac0f75..687f89a35 100644 --- a/vendor/github.com/google/go-github/github/migrations_test.go +++ b/vendor/github.com/google/go-github/github/migrations_test.go @@ -15,7 +15,7 @@ import ( ) func TestMigrationService_StartMigration(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestMigrationService_StartMigration(t *testing.T) { } func TestMigrationService_ListMigrations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations", func(w http.ResponseWriter, r *http.Request) { @@ -61,7 +61,7 @@ func TestMigrationService_ListMigrations(t *testing.T) { } func TestMigrationService_MigrationStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1", func(w http.ResponseWriter, r *http.Request) { @@ -82,7 +82,7 @@ func TestMigrationService_MigrationStatus(t *testing.T) { } func TestMigrationService_MigrationArchiveURL(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { @@ -108,7 +108,7 @@ func TestMigrationService_MigrationArchiveURL(t *testing.T) { } func TestMigrationService_DeleteMigration(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { @@ -124,7 +124,7 @@ func TestMigrationService_DeleteMigration(t *testing.T) { } func TestMigrationService_UnlockRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/repos/r/lock", func(w http.ResponseWriter, r *http.Request) { @@ -159,7 +159,7 @@ var migrationJSON = []byte(`{ }`) var wantMigration = &Migration{ - ID: Int(79), + ID: Int64(79), GUID: String("0b989ba4-242f-11e5-81e1-c7b6966d2516"), State: String("pending"), LockRepositories: Bool(true), @@ -169,7 +169,7 @@ var wantMigration = &Migration{ UpdatedAt: String("2015-07-06T15:33:38-07:00"), Repositories: []*Repository{ { - ID: Int(1296269), + ID: Int64(1296269), Name: String("Hello-World"), FullName: String("octocat/Hello-World"), Description: String("This your first repo!"), diff --git a/vendor/github.com/google/go-github/github/migrations_user.go b/vendor/github.com/google/go-github/github/migrations_user.go new file mode 100644 index 000000000..ae53e6870 --- /dev/null +++ b/vendor/github.com/google/go-github/github/migrations_user.go @@ -0,0 +1,214 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "errors" + "fmt" + "net/http" +) + +// UserMigration represents a GitHub migration (archival). +type UserMigration struct { + ID *int64 `json:"id,omitempty"` + GUID *string `json:"guid,omitempty"` + // State is the current state of a migration. + // Possible values are: + // "pending" which means the migration hasn't started yet, + // "exporting" which means the migration is in progress, + // "exported" which means the migration finished successfully, or + // "failed" which means the migration failed. + State *string `json:"state,omitempty"` + // LockRepositories indicates whether repositories are locked (to prevent + // manipulation) while migrating data. + LockRepositories *bool `json:"lock_repositories,omitempty"` + // ExcludeAttachments indicates whether attachments should be excluded from + // the migration (to reduce migration archive file size). + ExcludeAttachments *bool `json:"exclude_attachments,omitempty"` + URL *string `json:"url,omitempty"` + CreatedAt *string `json:"created_at,omitempty"` + UpdatedAt *string `json:"updated_at,omitempty"` + Repositories []*Repository `json:"repositories,omitempty"` +} + +func (m UserMigration) String() string { + return Stringify(m) +} + +// UserMigrationOptions specifies the optional parameters to Migration methods. +type UserMigrationOptions struct { + // LockRepositories indicates whether repositories should be locked (to prevent + // manipulation) while migrating data. + LockRepositories bool + + // ExcludeAttachments indicates whether attachments should be excluded from + // the migration (to reduce migration archive file size). + ExcludeAttachments bool +} + +// startUserMigration represents the body of a StartMigration request. +type startUserMigration struct { + // Repositories is a slice of repository names to migrate. + Repositories []string `json:"repositories,omitempty"` + + // LockRepositories indicates whether repositories should be locked (to prevent + // manipulation) while migrating data. + LockRepositories *bool `json:"lock_repositories,omitempty"` + + // ExcludeAttachments indicates whether attachments should be excluded from + // the migration (to reduce migration archive file size). + ExcludeAttachments *bool `json:"exclude_attachments,omitempty"` +} + +// StartUserMigration starts the generation of a migration archive. +// repos is a slice of repository names to migrate. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#start-a-user-migration +func (s *MigrationService) StartUserMigration(ctx context.Context, repos []string, opt *UserMigrationOptions) (*UserMigration, *Response, error) { + u := "user/migrations" + + body := &startUserMigration{Repositories: repos} + if opt != nil { + body.LockRepositories = Bool(opt.LockRepositories) + body.ExcludeAttachments = Bool(opt.ExcludeAttachments) + } + + req, err := s.client.NewRequest("POST", u, body) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + m := &UserMigration{} + resp, err := s.client.Do(ctx, req, m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// ListUserMigrations lists the most recent migrations. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#get-a-list-of-user-migrations +func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigration, *Response, error) { + u := "user/migrations" + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + var m []*UserMigration + resp, err := s.client.Do(ctx, req, &m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// UserMigrationStatus gets the status of a specific migration archive. +// id is the migration ID. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#get-the-status-of-a-user-migration +func (s *MigrationService) UserMigrationStatus(ctx context.Context, id int64) (*UserMigration, *Response, error) { + u := fmt.Sprintf("user/migrations/%v", id) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + m := &UserMigration{} + resp, err := s.client.Do(ctx, req, m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// UserMigrationArchiveURL gets the URL for a specific migration archive. +// id is the migration ID. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#download-a-user-migration-archive +func (s *MigrationService) UserMigrationArchiveURL(ctx context.Context, id int64) (string, error) { + url := fmt.Sprintf("user/migrations/%v/archive", id) + + req, err := s.client.NewRequest("GET", url, nil) + if err != nil { + return "", err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + m := &UserMigration{} + + var loc string + originalRedirect := s.client.client.CheckRedirect + s.client.client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + loc = req.URL.String() + return http.ErrUseLastResponse + } + defer func() { + s.client.client.CheckRedirect = originalRedirect + }() + resp, err := s.client.Do(ctx, req, m) + if err == nil { + return "", errors.New("expected redirect, none provided") + } + loc = resp.Header.Get("Location") + return loc, nil +} + +// DeleteUserMigration will delete a previous migration archive. +// id is the migration ID. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#delete-a-user-migration-archive +func (s *MigrationService) DeleteUserMigration(ctx context.Context, id int64) (*Response, error) { + url := fmt.Sprintf("user/migrations/%v/archive", id) + + req, err := s.client.NewRequest("DELETE", url, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + return s.client.Do(ctx, req, nil) +} + +// UnlockUserRepository will unlock a repo that was locked for migration. +// id is migration ID. +// You should unlock each migrated repository and delete them when the migration +// is complete and you no longer need the source data. +// +// GitHub API docs: https://developer.github.com/v3/migrations/users/#unlock-a-user-repository +func (s *MigrationService) UnlockUserRepo(ctx context.Context, id int64, repo string) (*Response, error) { + url := fmt.Sprintf("user/migrations/%v/repos/%v/lock", id, repo) + + req, err := s.client.NewRequest("DELETE", url, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMigrationsPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/migrations_user_test.go b/vendor/github.com/google/go-github/github/migrations_user_test.go new file mode 100644 index 000000000..c271e02a8 --- /dev/null +++ b/vendor/github.com/google/go-github/github/migrations_user_test.go @@ -0,0 +1,197 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" + "reflect" + "strings" + "testing" +) + +func TestMigrationService_StartUserMigration(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + w.WriteHeader(http.StatusCreated) + w.Write(userMigrationJSON) + }) + + opt := &UserMigrationOptions{ + LockRepositories: true, + ExcludeAttachments: false, + } + + got, _, err := client.Migrations.StartUserMigration(context.Background(), []string{"r"}, opt) + if err != nil { + t.Errorf("StartUserMigration returned error: %v", err) + } + + want := wantUserMigration + if !reflect.DeepEqual(want, got) { + t.Errorf("StartUserMigration = %v, want = %v", got, want) + } +} + +func TestMigrationService_ListUserMigrations(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + w.WriteHeader(http.StatusOK) + w.Write([]byte(fmt.Sprintf("[%s]", userMigrationJSON))) + }) + + got, _, err := client.Migrations.ListUserMigrations(context.Background()) + if err != nil { + t.Errorf("ListUserMigrations returned error %v", err) + } + + want := []*UserMigration{wantUserMigration} + if !reflect.DeepEqual(want, got) { + t.Errorf("ListUserMigrations = %v, want = %v", got, want) + } +} + +func TestMigrationService_UserMigrationStatus(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + w.WriteHeader(http.StatusOK) + w.Write(userMigrationJSON) + }) + + got, _, err := client.Migrations.UserMigrationStatus(context.Background(), 1) + if err != nil { + t.Errorf("UserMigrationStatus returned error %v", err) + } + + want := wantUserMigration + if !reflect.DeepEqual(want, got) { + t.Errorf("UserMigrationStatus = %v, want = %v", got, want) + } +} + +func TestMigrationService_UserMigrationArchiveURL(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + http.Redirect(w, r, "/go-github", http.StatusFound) + }) + + mux.HandleFunc("/go-github", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + + w.WriteHeader(http.StatusOK) + }) + + got, err := client.Migrations.UserMigrationArchiveURL(context.Background(), 1) + if err != nil { + t.Errorf("UserMigrationArchiveURL returned error %v", err) + } + + want := "/go-github" + if !strings.HasSuffix(got, want) { + t.Errorf("UserMigrationArchiveURL = %v, want = %v", got, want) + } +} + +func TestMigrationService_DeleteUserMigration(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + w.WriteHeader(http.StatusNoContent) + }) + + got, err := client.Migrations.DeleteUserMigration(context.Background(), 1) + if err != nil { + t.Errorf("DeleteUserMigration returned error %v", err) + } + + if got.StatusCode != http.StatusNoContent { + t.Errorf("DeleteUserMigration returned status = %v, want = %v", got.StatusCode, http.StatusNoContent) + } +} + +func TestMigrationService_UnlockUserRepo(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/migrations/1/repos/r/lock", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeMigrationsPreview) + + w.WriteHeader(http.StatusNoContent) + }) + + got, err := client.Migrations.UnlockUserRepo(context.Background(), 1, "r") + if err != nil { + t.Errorf("UnlockUserRepo returned error %v", err) + } + + if got.StatusCode != http.StatusNoContent { + t.Errorf("UnlockUserRepo returned status = %v, want = %v", got.StatusCode, http.StatusNoContent) + } +} + +var userMigrationJSON = []byte(`{ + "id": 79, + "guid": "0b989ba4-242f-11e5-81e1-c7b6966d2516", + "state": "pending", + "lock_repositories": true, + "exclude_attachments": false, + "url": "https://api.github.com/orgs/octo-org/migrations/79", + "created_at": "2015-07-06T15:33:38-07:00", + "updated_at": "2015-07-06T15:33:38-07:00", + "repositories": [ + { + "id": 1296269, + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "description": "This your first repo!" + } + ] +}`) + +var wantUserMigration = &UserMigration{ + ID: Int64(79), + GUID: String("0b989ba4-242f-11e5-81e1-c7b6966d2516"), + State: String("pending"), + LockRepositories: Bool(true), + ExcludeAttachments: Bool(false), + URL: String("https://api.github.com/orgs/octo-org/migrations/79"), + CreatedAt: String("2015-07-06T15:33:38-07:00"), + UpdatedAt: String("2015-07-06T15:33:38-07:00"), + Repositories: []*Repository{ + { + ID: Int64(1296269), + Name: String("Hello-World"), + FullName: String("octocat/Hello-World"), + Description: String("This your first repo!"), + }, + }, +} diff --git a/vendor/github.com/google/go-github/github/misc.go b/vendor/github.com/google/go-github/github/misc.go index 5b8082d3c..e9b0ea22a 100644 --- a/vendor/github.com/google/go-github/github/misc.go +++ b/vendor/github.com/google/go-github/github/misc.go @@ -158,6 +158,10 @@ type APIMeta struct { // An array of IP addresses in CIDR format specifying the addresses // which serve GitHub Pages websites. Pages []string `json:"pages,omitempty"` + + // An Array of IP addresses specifying the addresses that source imports + // will originate from on GitHub.com. + Importer []string `json:"importer,omitempty"` } // APIMeta returns information about GitHub.com, the service. Or, if you access diff --git a/vendor/github.com/google/go-github/github/misc_test.go b/vendor/github.com/google/go-github/github/misc_test.go index f2b2df44b..b7144f909 100644 --- a/vendor/github.com/google/go-github/github/misc_test.go +++ b/vendor/github.com/google/go-github/github/misc_test.go @@ -15,7 +15,7 @@ import ( ) func TestMarkdown(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &markdownRequest{ @@ -48,7 +48,7 @@ func TestMarkdown(t *testing.T) { } func TestListEmojis(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/emojis", func(w http.ResponseWriter, r *http.Request) { @@ -68,7 +68,7 @@ func TestListEmojis(t *testing.T) { } func TestListCodesOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/codes_of_conduct", func(w http.ResponseWriter, r *http.Request) { @@ -98,7 +98,7 @@ func TestListCodesOfConduct(t *testing.T) { } func TestGetCodeOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/codes_of_conduct/k", func(w http.ResponseWriter, r *http.Request) { @@ -129,12 +129,12 @@ func TestGetCodeOfConduct(t *testing.T) { } func TestAPIMeta(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/meta", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "pages":["p"], "verifiable_password_authentication": true}`) + fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "pages":["p"], "importer":["i"], "verifiable_password_authentication": true}`) }) meta, _, err := client.APIMeta(context.Background()) @@ -143,9 +143,11 @@ func TestAPIMeta(t *testing.T) { } want := &APIMeta{ - Hooks: []string{"h"}, - Git: []string{"g"}, - Pages: []string{"p"}, + Hooks: []string{"h"}, + Git: []string{"g"}, + Pages: []string{"p"}, + Importer: []string{"i"}, + VerifiablePasswordAuthentication: Bool(true), } if !reflect.DeepEqual(want, meta) { @@ -154,7 +156,7 @@ func TestAPIMeta(t *testing.T) { } func TestOctocat(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := "input" @@ -178,7 +180,7 @@ func TestOctocat(t *testing.T) { } func TestZen(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() output := "sample text" @@ -200,7 +202,7 @@ func TestZen(t *testing.T) { } func TestListServiceHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/hooks", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/orgs.go b/vendor/github.com/google/go-github/github/orgs.go index e6947c96c..c70039ba0 100644 --- a/vendor/github.com/google/go-github/github/orgs.go +++ b/vendor/github.com/google/go-github/github/orgs.go @@ -19,30 +19,42 @@ type OrganizationsService service // Organization represents a GitHub organization account. type Organization struct { - Login *string `json:"login,omitempty"` - ID *int `json:"id,omitempty"` - AvatarURL *string `json:"avatar_url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - Name *string `json:"name,omitempty"` - Company *string `json:"company,omitempty"` - Blog *string `json:"blog,omitempty"` - Location *string `json:"location,omitempty"` - Email *string `json:"email,omitempty"` - Description *string `json:"description,omitempty"` - PublicRepos *int `json:"public_repos,omitempty"` - PublicGists *int `json:"public_gists,omitempty"` - Followers *int `json:"followers,omitempty"` - Following *int `json:"following,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - TotalPrivateRepos *int `json:"total_private_repos,omitempty"` - OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"` - PrivateGists *int `json:"private_gists,omitempty"` - DiskUsage *int `json:"disk_usage,omitempty"` - Collaborators *int `json:"collaborators,omitempty"` - BillingEmail *string `json:"billing_email,omitempty"` - Type *string `json:"type,omitempty"` - Plan *Plan `json:"plan,omitempty"` + Login *string `json:"login,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + AvatarURL *string `json:"avatar_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + Name *string `json:"name,omitempty"` + Company *string `json:"company,omitempty"` + Blog *string `json:"blog,omitempty"` + Location *string `json:"location,omitempty"` + Email *string `json:"email,omitempty"` + Description *string `json:"description,omitempty"` + PublicRepos *int `json:"public_repos,omitempty"` + PublicGists *int `json:"public_gists,omitempty"` + Followers *int `json:"followers,omitempty"` + Following *int `json:"following,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + TotalPrivateRepos *int `json:"total_private_repos,omitempty"` + OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"` + PrivateGists *int `json:"private_gists,omitempty"` + DiskUsage *int `json:"disk_usage,omitempty"` + Collaborators *int `json:"collaborators,omitempty"` + BillingEmail *string `json:"billing_email,omitempty"` + Type *string `json:"type,omitempty"` + Plan *Plan `json:"plan,omitempty"` + TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"` + + // DefaultRepoPermission can be one of: "read", "write", "admin", or "none". (Default: "read"). + // It is only used in OrganizationsService.Edit. + DefaultRepoPermission *string `json:"default_repository_permission,omitempty"` + // DefaultRepoSettings can be one of: "read", "write", "admin", or "none". (Default: "read"). + // It is only used in OrganizationsService.Get. + DefaultRepoSettings *string `json:"default_repository_settings,omitempty"` + + // MembersCanCreateRepos default value is true and is only used in Organizations.Edit. + MembersCanCreateRepos *bool `json:"members_can_create_repositories,omitempty"` // API URLs URL *string `json:"url,omitempty"` @@ -74,8 +86,11 @@ func (p Plan) String() string { // OrganizationsService.ListAll method. type OrganizationsListOptions struct { // Since filters Organizations by ID. - Since int `url:"since,omitempty"` + Since int64 `url:"since,omitempty"` + // Note: Pagination is powered exclusively by the Since parameter, + // ListOptions.Page has no effect. + // ListOptions.PerPage controls an undocumented GitHub API parameter. ListOptions } @@ -157,7 +172,7 @@ func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organizati // GetByID fetches an organization. // // Note: GetByID uses the undocumented GitHub API endpoint /organizations/:id. -func (s *OrganizationsService) GetByID(ctx context.Context, id int) (*Organization, *Response, error) { +func (s *OrganizationsService) GetByID(ctx context.Context, id int64) (*Organization, *Response, error) { u := fmt.Sprintf("organizations/%d", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/orgs_hooks.go b/vendor/github.com/google/go-github/github/orgs_hooks.go index 4fc692e0f..b710ea402 100644 --- a/vendor/github.com/google/go-github/github/orgs_hooks.go +++ b/vendor/github.com/google/go-github/github/orgs_hooks.go @@ -37,7 +37,7 @@ func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opt *L // GetHook returns a single specified Hook. // // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#get-single-hook -func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int) (*Hook, *Response, error) { +func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64) (*Hook, *Response, error) { u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -49,12 +49,22 @@ func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int) } // CreateHook creates a Hook for the specified org. -// Name and Config are required fields. +// Config is a required field. +// +// Note that only a subset of the hook fields are used and hook must +// not be nil. // // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-a-hook func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) { u := fmt.Sprintf("orgs/%v/hooks", org) - req, err := s.client.NewRequest("POST", u, hook) + + hookReq := &createHookRequest{ + Events: hook.Events, + Active: hook.Active, + Config: hook.Config, + } + + req, err := s.client.NewRequest("POST", u, hookReq) if err != nil { return nil, nil, err } @@ -71,7 +81,7 @@ func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook // EditHook updates a specified Hook. // // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#edit-a-hook -func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int, hook *Hook) (*Hook, *Response, error) { +func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int64, hook *Hook) (*Hook, *Response, error) { u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) req, err := s.client.NewRequest("PATCH", u, hook) if err != nil { @@ -85,7 +95,7 @@ func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int, // PingHook triggers a 'ping' event to be sent to the Hook. // // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#ping-a-hook -func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int) (*Response, error) { +func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int64) (*Response, error) { u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id) req, err := s.client.NewRequest("POST", u, nil) if err != nil { @@ -97,7 +107,7 @@ func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int) // DeleteHook deletes a specified Hook. // // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#delete-a-hook -func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int) (*Response, error) { +func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int64) (*Response, error) { u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/orgs_hooks_test.go b/vendor/github.com/google/go-github/github/orgs_hooks_test.go index 69e75f9f4..50caee897 100644 --- a/vendor/github.com/google/go-github/github/orgs_hooks_test.go +++ b/vendor/github.com/google/go-github/github/orgs_hooks_test.go @@ -15,7 +15,7 @@ import ( ) func TestOrganizationsService_ListHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks", func(w http.ResponseWriter, r *http.Request) { @@ -31,19 +31,52 @@ func TestOrganizationsService_ListHooks(t *testing.T) { t.Errorf("Organizations.ListHooks returned error: %v", err) } - want := []*Hook{{ID: Int(1)}, {ID: Int(2)}} + want := []*Hook{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(hooks, want) { t.Errorf("Organizations.ListHooks returned %+v, want %+v", hooks, want) } } func TestOrganizationsService_ListHooks_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListHooks(context.Background(), "%", nil) testURLParseError(t, err) } +func TestOrganizationsService_CreateHook(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &Hook{CreatedAt: &referenceTime} + + mux.HandleFunc("/orgs/o/hooks", func(w http.ResponseWriter, r *http.Request) { + v := new(createHookRequest) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + want := &createHookRequest{} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + hook, _, err := client.Organizations.CreateHook(context.Background(), "o", input) + if err != nil { + t.Errorf("Organizations.CreateHook returned error: %v", err) + } + + want := &Hook{ID: Int64(1)} + if !reflect.DeepEqual(hook, want) { + t.Errorf("Organizations.CreateHook returned %+v, want %+v", hook, want) + } +} + func TestOrganizationsService_GetHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -56,22 +89,25 @@ func TestOrganizationsService_GetHook(t *testing.T) { t.Errorf("Organizations.GetHook returned error: %v", err) } - want := &Hook{ID: Int(1)} + want := &Hook{ID: Int64(1)} if !reflect.DeepEqual(hook, want) { t.Errorf("Organizations.GetHook returned %+v, want %+v", hook, want) } } func TestOrganizationsService_GetHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.GetHook(context.Background(), "%", 1) testURLParseError(t, err) } func TestOrganizationsService_EditHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &Hook{Name: String("t")} + input := &Hook{} mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { v := new(Hook) @@ -90,19 +126,22 @@ func TestOrganizationsService_EditHook(t *testing.T) { t.Errorf("Organizations.EditHook returned error: %v", err) } - want := &Hook{ID: Int(1)} + want := &Hook{ID: Int64(1)} if !reflect.DeepEqual(hook, want) { t.Errorf("Organizations.EditHook returned %+v, want %+v", hook, want) } } func TestOrganizationsService_EditHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.EditHook(context.Background(), "%", 1, nil) testURLParseError(t, err) } func TestOrganizationsService_PingHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { @@ -116,7 +155,7 @@ func TestOrganizationsService_PingHook(t *testing.T) { } func TestOrganizationsService_DeleteHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -130,6 +169,9 @@ func TestOrganizationsService_DeleteHook(t *testing.T) { } func TestOrganizationsService_DeleteHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.DeleteHook(context.Background(), "%", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/orgs_members.go b/vendor/github.com/google/go-github/github/orgs_members.go index d0ea6a985..d18435999 100644 --- a/vendor/github.com/google/go-github/github/orgs_members.go +++ b/vendor/github.com/google/go-github/github/orgs_members.go @@ -59,7 +59,7 @@ type ListMembersOptions struct { // Possible values are: // all - all members of the organization, regardless of role // admin - organization owners - // member - non-organization members + // member - non-owner organization members // // Default is "all". Role string `url:"role,omitempty"` @@ -297,3 +297,74 @@ func (s *OrganizationsService) ListPendingOrgInvitations(ctx context.Context, or } return pendingInvitations, resp, nil } + +// CreateOrgInvitationOptions specifies the parameters to the OrganizationService.Invite +// method. +type CreateOrgInvitationOptions struct { + // GitHub user ID for the person you are inviting. Not required if you provide Email. + InviteeID *int64 `json:"invitee_id,omitempty"` + // Email address of the person you are inviting, which can be an existing GitHub user. + // Not required if you provide InviteeID + Email *string `json:"email,omitempty"` + // Specify role for new member. Can be one of: + // * admin - Organization owners with full administrative rights to the + // organization and complete access to all repositories and teams. + // * direct_member - Non-owner organization members with ability to see + // other members and join teams by invitation. + // * billing_manager - Non-owner organization members with ability to + // manage the billing settings of your organization. + // Default is "direct_member". + Role *string `json:"role"` + TeamID []int64 `json:"team_ids"` +} + +// CreateOrgInvitation invites people to an organization by using their GitHub user ID or their email address. +// In order to create invitations in an organization, +// the authenticated user must be an organization owner. +// +// https://developer.github.com/v3/orgs/members/#create-organization-invitation +func (s *OrganizationsService) CreateOrgInvitation(ctx context.Context, org string, opt *CreateOrgInvitationOptions) (*Invitation, *Response, error) { + u := fmt.Sprintf("orgs/%v/invitations", org) + + req, err := s.client.NewRequest("POST", u, opt) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeOrganizationInvitationPreview) + + var invitation *Invitation + resp, err := s.client.Do(ctx, req, &invitation) + if err != nil { + return nil, resp, err + } + return invitation, resp, nil +} + +// ListOrgInvitationTeams lists all teams associated with an invitation. In order to see invitations in an organization, +// the authenticated user must be an organization owner. +// +// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-organization-invitation-teams +func (s *OrganizationsService) ListOrgInvitationTeams(ctx context.Context, org, invitationID string, opt *ListOptions) ([]*Team, *Response, error) { + u := fmt.Sprintf("orgs/%v/invitations/%v/teams", org, invitationID) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeOrganizationInvitationPreview) + + var orgInvitationTeams []*Team + resp, err := s.client.Do(ctx, req, &orgInvitationTeams) + if err != nil { + return nil, resp, err + } + return orgInvitationTeams, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/orgs_members_test.go b/vendor/github.com/google/go-github/github/orgs_members_test.go index 21fbeeaf3..e524d03f1 100644 --- a/vendor/github.com/google/go-github/github/orgs_members_test.go +++ b/vendor/github.com/google/go-github/github/orgs_members_test.go @@ -16,7 +16,7 @@ import ( ) func TestOrganizationsService_ListMembers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) { @@ -40,19 +40,22 @@ func TestOrganizationsService_ListMembers(t *testing.T) { t.Errorf("Organizations.ListMembers returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(members, want) { t.Errorf("Organizations.ListMembers returned %+v, want %+v", members, want) } } func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListMembers(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_ListMembers_public(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members", func(w http.ResponseWriter, r *http.Request) { @@ -66,14 +69,14 @@ func TestOrganizationsService_ListMembers_public(t *testing.T) { t.Errorf("Organizations.ListMembers returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(members, want) { t.Errorf("Organizations.ListMembers returned %+v, want %+v", members, want) } } func TestOrganizationsService_IsMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -92,7 +95,7 @@ func TestOrganizationsService_IsMember(t *testing.T) { // ensure that a 404 response is interpreted as "false" and not an error func TestOrganizationsService_IsMember_notMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -112,7 +115,7 @@ func TestOrganizationsService_IsMember_notMember(t *testing.T) { // ensure that a 400 response is interpreted as an actual error, and not simply // as "false" like the above case of a 404 func TestOrganizationsService_IsMember_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -130,12 +133,15 @@ func TestOrganizationsService_IsMember_error(t *testing.T) { } func TestOrganizationsService_IsMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_IsPublicMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -154,7 +160,7 @@ func TestOrganizationsService_IsPublicMember(t *testing.T) { // ensure that a 404 response is interpreted as "false" and not an error func TestOrganizationsService_IsPublicMember_notMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -174,7 +180,7 @@ func TestOrganizationsService_IsPublicMember_notMember(t *testing.T) { // ensure that a 400 response is interpreted as an actual error, and not simply // as "false" like the above case of a 404 func TestOrganizationsService_IsPublicMember_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -192,12 +198,15 @@ func TestOrganizationsService_IsPublicMember_error(t *testing.T) { } func TestOrganizationsService_IsPublicMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsPublicMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_RemoveMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -211,12 +220,15 @@ func TestOrganizationsService_RemoveMember(t *testing.T) { } func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.RemoveMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_ListOrgMemberships(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/memberships/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -244,7 +256,7 @@ func TestOrganizationsService_ListOrgMemberships(t *testing.T) { } func TestOrganizationsService_GetOrgMembership_AuthenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/memberships/orgs/o", func(w http.ResponseWriter, r *http.Request) { @@ -264,7 +276,7 @@ func TestOrganizationsService_GetOrgMembership_AuthenticatedUser(t *testing.T) { } func TestOrganizationsService_GetOrgMembership_SpecifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -284,7 +296,7 @@ func TestOrganizationsService_GetOrgMembership_SpecifiedUser(t *testing.T) { } func TestOrganizationsService_EditOrgMembership_AuthenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Membership{State: String("active")} @@ -313,7 +325,7 @@ func TestOrganizationsService_EditOrgMembership_AuthenticatedUser(t *testing.T) } func TestOrganizationsService_EditOrgMembership_SpecifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Membership{State: String("active")} @@ -342,7 +354,7 @@ func TestOrganizationsService_EditOrgMembership_SpecifiedUser(t *testing.T) { } func TestOrganizationsService_RemoveOrgMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -357,7 +369,7 @@ func TestOrganizationsService_RemoveOrgMembership(t *testing.T) { } func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/invitations", func(w http.ResponseWriter, r *http.Request) { @@ -388,7 +400,9 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { "received_events_url": "https://api.github.com/users/other_user/received_events/privacy", "type": "User", "site_admin": false - } + }, + "team_count": 2, + "invitation_team_url": "https://api.github.com/organizations/2/invitations/1/teams" } ]`) }) @@ -399,17 +413,17 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { t.Errorf("Organizations.ListPendingOrgInvitations returned error: %v", err) } - createdAt := time.Date(2017, 01, 21, 0, 0, 0, 0, time.UTC) + createdAt := time.Date(2017, time.January, 21, 0, 0, 0, 0, time.UTC) want := []*Invitation{ { - ID: Int(1), + ID: Int64(1), Login: String("monalisa"), Email: String("octocat@github.com"), Role: String("direct_member"), CreatedAt: &createdAt, Inviter: &User{ Login: String("other_user"), - ID: Int(1), + ID: Int64(1), AvatarURL: String("https://github.com/images/error/other_user_happy.gif"), GravatarID: String(""), URL: String("https://api.github.com/users/other_user"), @@ -426,9 +440,96 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { Type: String("User"), SiteAdmin: Bool(false), }, + TeamCount: Int(2), + InvitationTeamURL: String("https://api.github.com/organizations/2/invitations/1/teams"), }} if !reflect.DeepEqual(invitations, want) { t.Errorf("Organizations.ListPendingOrgInvitations returned %+v, want %+v", invitations, want) } } + +func TestOrganizationsService_CreateOrgInvitation(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + input := &CreateOrgInvitationOptions{ + Email: String("octocat@github.com"), + Role: String("direct_member"), + TeamID: []int64{ + 12, + 26, + }, + } + + mux.HandleFunc("/orgs/o/invitations", func(w http.ResponseWriter, r *http.Request) { + v := new(CreateOrgInvitationOptions) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeOrganizationInvitationPreview) + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprintln(w, `{"email": "octocat@github.com"}`) + + }) + + invitations, _, err := client.Organizations.CreateOrgInvitation(context.Background(), "o", input) + if err != nil { + t.Errorf("Organizations.CreateOrgInvitation returned error: %v", err) + } + + want := &Invitation{Email: String("octocat@github.com")} + if !reflect.DeepEqual(invitations, want) { + t.Errorf("Organizations.ListPendingOrgInvitations returned %+v, want %+v", invitations, want) + } +} + +func TestOrganizationsService_ListOrgInvitationTeams(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/orgs/o/invitations/22/teams", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "1"}) + testHeader(t, r, "Accept", mediaTypeOrganizationInvitationPreview) + fmt.Fprint(w, `[ + { + "id": 1, + "url": "https://api.github.com/teams/1", + "name": "Justice League", + "slug": "justice-league", + "description": "A great team.", + "privacy": "closed", + "permission": "admin", + "members_url": "https://api.github.com/teams/1/members{/member}", + "repositories_url": "https://api.github.com/teams/1/repos" + } + ]`) + }) + + opt := &ListOptions{Page: 1} + invitations, _, err := client.Organizations.ListOrgInvitationTeams(context.Background(), "o", "22", opt) + if err != nil { + t.Errorf("Organizations.ListOrgInvitationTeams returned error: %v", err) + } + + want := []*Team{ + { + ID: Int64(1), + URL: String("https://api.github.com/teams/1"), + Name: String("Justice League"), + Slug: String("justice-league"), + Description: String("A great team."), + Privacy: String("closed"), + Permission: String("admin"), + MembersURL: String("https://api.github.com/teams/1/members{/member}"), + RepositoriesURL: String("https://api.github.com/teams/1/repos"), + }, + } + + if !reflect.DeepEqual(invitations, want) { + t.Errorf("Organizations.ListOrgInvitationTeams returned %+v, want %+v", invitations, want) + } +} diff --git a/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go b/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go index e34f8653b..85ffd05f6 100644 --- a/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go +++ b/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go @@ -48,3 +48,34 @@ func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org return members, resp, nil } + +// RemoveOutsideCollaborator removes a user from the list of outside collaborators; +// consequently, removing them from all the organization's repositories. +// +// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator +func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { + u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// ConvertMemberToOutsideCollaborator reduces the permission level of a member of the +// organization to that of an outside collaborator. Therefore, they will only +// have access to the repositories that their current team membership allows. +// Responses for converting a non-member or the last owner to an outside collaborator +// are listed in GitHub API docs. +// +// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#convert-member-to-outside-collaborator +func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { + u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) + req, err := s.client.NewRequest("PUT", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/orgs_outside_collaborators_test.go b/vendor/github.com/google/go-github/github/orgs_outside_collaborators_test.go index 536006119..8b72feb21 100644 --- a/vendor/github.com/google/go-github/github/orgs_outside_collaborators_test.go +++ b/vendor/github.com/google/go-github/github/orgs_outside_collaborators_test.go @@ -14,7 +14,7 @@ import ( ) func TestOrganizationsService_ListOutsideCollaborators(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/outside_collaborators", func(w http.ResponseWriter, r *http.Request) { @@ -35,13 +35,100 @@ func TestOrganizationsService_ListOutsideCollaborators(t *testing.T) { t.Errorf("Organizations.ListOutsideCollaborators returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(members, want) { t.Errorf("Organizations.ListOutsideCollaborators returned %+v, want %+v", members, want) } } func TestOrganizationsService_ListOutsideCollaborators_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListOutsideCollaborators(context.Background(), "%", nil) testURLParseError(t, err) } + +func TestOrganizationsService_RemoveOutsideCollaborator(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + } + mux.HandleFunc("/orgs/o/outside_collaborators/u", handler) + + _, err := client.Organizations.RemoveOutsideCollaborator(context.Background(), "o", "u") + if err != nil { + t.Errorf("Organizations.RemoveOutsideCollaborator returned error: %v", err) + } +} + +func TestOrganizationsService_RemoveOutsideCollaborator_NonMember(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNotFound) + } + mux.HandleFunc("/orgs/o/outside_collaborators/u", handler) + + _, err := client.Organizations.RemoveOutsideCollaborator(context.Background(), "o", "u") + if err, ok := err.(*ErrorResponse); !ok { + t.Errorf("Organizations.RemoveOutsideCollaborator did not return an error") + } else if err.Response.StatusCode != http.StatusNotFound { + t.Errorf("Organizations.RemoveOutsideCollaborator did not return 404 status code") + } +} + +func TestOrganizationsService_RemoveOutsideCollaborator_Member(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusUnprocessableEntity) + } + mux.HandleFunc("/orgs/o/outside_collaborators/u", handler) + + _, err := client.Organizations.RemoveOutsideCollaborator(context.Background(), "o", "u") + if err, ok := err.(*ErrorResponse); !ok { + t.Errorf("Organizations.RemoveOutsideCollaborator did not return an error") + } else if err.Response.StatusCode != http.StatusUnprocessableEntity { + t.Errorf("Organizations.RemoveOutsideCollaborator did not return 422 status code") + } +} + +func TestOrganizationsService_ConvertMemberToOutsideCollaborator(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + } + mux.HandleFunc("/orgs/o/outside_collaborators/u", handler) + + _, err := client.Organizations.ConvertMemberToOutsideCollaborator(context.Background(), "o", "u") + if err != nil { + t.Errorf("Organizations.ConvertMemberToOutsideCollaborator returned error: %v", err) + } +} + +func TestOrganizationsService_ConvertMemberToOutsideCollaborator_NonMemberOrLastOwner(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + w.WriteHeader(http.StatusForbidden) + } + mux.HandleFunc("/orgs/o/outside_collaborators/u", handler) + + _, err := client.Organizations.ConvertMemberToOutsideCollaborator(context.Background(), "o", "u") + if err, ok := err.(*ErrorResponse); !ok { + t.Errorf("Organizations.ConvertMemberToOutsideCollaborator did not return an error") + } else if err.Response.StatusCode != http.StatusForbidden { + t.Errorf("Organizations.ConvertMemberToOutsideCollaborator did not return 403 status code") + } +} diff --git a/vendor/github.com/google/go-github/github/orgs_projects_test.go b/vendor/github.com/google/go-github/github/orgs_projects_test.go index 533f69196..efea5cb41 100644 --- a/vendor/github.com/google/go-github/github/orgs_projects_test.go +++ b/vendor/github.com/google/go-github/github/orgs_projects_test.go @@ -15,7 +15,7 @@ import ( ) func TestOrganizationsService_ListProjects(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/projects", func(w http.ResponseWriter, r *http.Request) { @@ -31,17 +31,17 @@ func TestOrganizationsService_ListProjects(t *testing.T) { t.Errorf("Organizations.ListProjects returned error: %v", err) } - want := []*Project{{ID: Int(1)}} + want := []*Project{{ID: Int64(1)}} if !reflect.DeepEqual(projects, want) { t.Errorf("Organizations.ListProjects returned %+v, want %+v", projects, want) } } func TestOrganizationsService_CreateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &ProjectOptions{Name: "Project Name", Body: "Project body."} + input := &ProjectOptions{Name: String("Project Name"), Body: String("Project body.")} mux.HandleFunc("/orgs/o/projects", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -61,7 +61,7 @@ func TestOrganizationsService_CreateProject(t *testing.T) { t.Errorf("Organizations.CreateProject returned error: %v", err) } - want := &Project{ID: Int(1)} + want := &Project{ID: Int64(1)} if !reflect.DeepEqual(project, want) { t.Errorf("Organizations.CreateProject returned %+v, want %+v", project, want) } diff --git a/vendor/github.com/google/go-github/github/orgs_teams.go b/vendor/github.com/google/go-github/github/orgs_teams.go deleted file mode 100644 index 684e2daff..000000000 --- a/vendor/github.com/google/go-github/github/orgs_teams.go +++ /dev/null @@ -1,431 +0,0 @@ -// Copyright 2013 The go-github AUTHORS. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package github - -import ( - "context" - "fmt" - "time" -) - -// Team represents a team within a GitHub organization. Teams are used to -// manage access to an organization's repositories. -type Team struct { - ID *int `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - URL *string `json:"url,omitempty"` - Slug *string `json:"slug,omitempty"` - - // Permission is deprecated when creating or editing a team in an org - // using the new GitHub permission model. It no longer identifies the - // permission a team has on its repos, but only specifies the default - // permission a repo is initially added with. Avoid confusion by - // specifying a permission value when calling AddTeamRepo. - Permission *string `json:"permission,omitempty"` - - // Privacy identifies the level of privacy this team should have. - // Possible values are: - // secret - only visible to organization owners and members of this team - // closed - visible to all members of this organization - // Default is "secret". - Privacy *string `json:"privacy,omitempty"` - - MembersCount *int `json:"members_count,omitempty"` - ReposCount *int `json:"repos_count,omitempty"` - Organization *Organization `json:"organization,omitempty"` - MembersURL *string `json:"members_url,omitempty"` - RepositoriesURL *string `json:"repositories_url,omitempty"` - - // LDAPDN is only available in GitHub Enterprise and when the team - // membership is synchronized with LDAP. - LDAPDN *string `json:"ldap_dn,omitempty"` -} - -func (t Team) String() string { - return Stringify(t) -} - -// Invitation represents a team member's invitation status. -type Invitation struct { - ID *int `json:"id,omitempty"` - Login *string `json:"login,omitempty"` - Email *string `json:"email,omitempty"` - // Role can be one of the values - 'direct_member', 'admin', 'billing_manager', 'hiring_manager', or 'reinstate'. - Role *string `json:"role,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - Inviter *User `json:"inviter,omitempty"` -} - -func (i Invitation) String() string { - return Stringify(i) -} - -// ListTeams lists all of the teams for an organization. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-teams -func (s *OrganizationsService) ListTeams(ctx context.Context, org string, opt *ListOptions) ([]*Team, *Response, error) { - u := fmt.Sprintf("orgs/%v/teams", org) - u, err := addOptions(u, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var teams []*Team - resp, err := s.client.Do(ctx, req, &teams) - if err != nil { - return nil, resp, err - } - - return teams, resp, nil -} - -// GetTeam fetches a team by ID. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team -func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *Response, error) { - u := fmt.Sprintf("teams/%v", team) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - t := new(Team) - resp, err := s.client.Do(ctx, req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil -} - -// CreateTeam creates a new team within an organization. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#create-team -func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *Team) (*Team, *Response, error) { - u := fmt.Sprintf("orgs/%v/teams", org) - req, err := s.client.NewRequest("POST", u, team) - if err != nil { - return nil, nil, err - } - - t := new(Team) - resp, err := s.client.Do(ctx, req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil -} - -// EditTeam edits a team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#edit-team -func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team) (*Team, *Response, error) { - u := fmt.Sprintf("teams/%v", id) - req, err := s.client.NewRequest("PATCH", u, team) - if err != nil { - return nil, nil, err - } - - t := new(Team) - resp, err := s.client.Do(ctx, req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil -} - -// DeleteTeam deletes a team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#delete-team -func (s *OrganizationsService) DeleteTeam(ctx context.Context, team int) (*Response, error) { - u := fmt.Sprintf("teams/%v", team) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// OrganizationListTeamMembersOptions specifies the optional parameters to the -// OrganizationsService.ListTeamMembers method. -type OrganizationListTeamMembersOptions struct { - // Role filters members returned by their role in the team. Possible - // values are "all", "member", "maintainer". Default is "all". - Role string `url:"role,omitempty"` - - ListOptions -} - -// ListTeamMembers lists all of the users who are members of the specified -// team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-members -func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int, opt *OrganizationListTeamMembersOptions) ([]*User, *Response, error) { - u := fmt.Sprintf("teams/%v/members", team) - u, err := addOptions(u, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var members []*User - resp, err := s.client.Do(ctx, req, &members) - if err != nil { - return nil, resp, err - } - - return members, resp, nil -} - -// IsTeamMember checks if a user is a member of the specified team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-member -func (s *OrganizationsService) IsTeamMember(ctx context.Context, team int, user string) (bool, *Response, error) { - u := fmt.Sprintf("teams/%v/members/%v", team, user) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return false, nil, err - } - - resp, err := s.client.Do(ctx, req, nil) - member, err := parseBoolResponse(err) - return member, resp, err -} - -// ListTeamRepos lists the repositories that the specified team has access to. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-repos -func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int, opt *ListOptions) ([]*Repository, *Response, error) { - u := fmt.Sprintf("teams/%v/repos", team) - u, err := addOptions(u, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - // TODO: remove custom Accept header when topics API fully launches. - req.Header.Set("Accept", mediaTypeTopicsPreview) - - var repos []*Repository - resp, err := s.client.Do(ctx, req, &repos) - if err != nil { - return nil, resp, err - } - - return repos, resp, nil -} - -// IsTeamRepo checks if a team manages the specified repository. If the -// repository is managed by team, a Repository is returned which includes the -// permissions team has for that repo. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#check-if-a-team-manages-a-repository -func (s *OrganizationsService) IsTeamRepo(ctx context.Context, team int, owner string, repo string) (*Repository, *Response, error) { - u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - req.Header.Set("Accept", mediaTypeOrgPermissionRepo) - - repository := new(Repository) - resp, err := s.client.Do(ctx, req, repository) - if err != nil { - return nil, resp, err - } - - return repository, resp, nil -} - -// OrganizationAddTeamRepoOptions specifies the optional parameters to the -// OrganizationsService.AddTeamRepo method. -type OrganizationAddTeamRepoOptions struct { - // Permission specifies the permission to grant the team on this repository. - // Possible values are: - // pull - team members can pull, but not push to or administer this repository - // push - team members can pull and push, but not administer this repository - // admin - team members can pull, push and administer this repository - // - // If not specified, the team's permission attribute will be used. - Permission string `json:"permission,omitempty"` -} - -// AddTeamRepo adds a repository to be managed by the specified team. The -// specified repository must be owned by the organization to which the team -// belongs, or a direct fork of a repository owned by the organization. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-repo -func (s *OrganizationsService) AddTeamRepo(ctx context.Context, team int, owner string, repo string, opt *OrganizationAddTeamRepoOptions) (*Response, error) { - u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) - req, err := s.client.NewRequest("PUT", u, opt) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// RemoveTeamRepo removes a repository from being managed by the specified -// team. Note that this does not delete the repository, it just removes it -// from the team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-repo -func (s *OrganizationsService) RemoveTeamRepo(ctx context.Context, team int, owner string, repo string) (*Response, error) { - u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// ListUserTeams lists a user's teams -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-user-teams -func (s *OrganizationsService) ListUserTeams(ctx context.Context, opt *ListOptions) ([]*Team, *Response, error) { - u := "user/teams" - u, err := addOptions(u, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var teams []*Team - resp, err := s.client.Do(ctx, req, &teams) - if err != nil { - return nil, resp, err - } - - return teams, resp, nil -} - -// GetTeamMembership returns the membership status for a user in a team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-membership -func (s *OrganizationsService) GetTeamMembership(ctx context.Context, team int, user string) (*Membership, *Response, error) { - u := fmt.Sprintf("teams/%v/memberships/%v", team, user) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - t := new(Membership) - resp, err := s.client.Do(ctx, req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil -} - -// OrganizationAddTeamMembershipOptions does stuff specifies the optional -// parameters to the OrganizationsService.AddTeamMembership method. -type OrganizationAddTeamMembershipOptions struct { - // Role specifies the role the user should have in the team. Possible - // values are: - // member - a normal member of the team - // maintainer - a team maintainer. Able to add/remove other team - // members, promote other team members to team - // maintainer, and edit the team’s name and description - // - // Default value is "member". - Role string `json:"role,omitempty"` -} - -// AddTeamMembership adds or invites a user to a team. -// -// In order to add a membership between a user and a team, the authenticated -// user must have 'admin' permissions to the team or be an owner of the -// organization that the team is associated with. -// -// If the user is already a part of the team's organization (meaning they're on -// at least one other team in the organization), this endpoint will add the -// user to the team. -// -// If the user is completely unaffiliated with the team's organization (meaning -// they're on none of the organization's teams), this endpoint will send an -// invitation to the user via email. This newly-created membership will be in -// the "pending" state until the user accepts the invitation, at which point -// the membership will transition to the "active" state and the user will be -// added as a member of the team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-membership -func (s *OrganizationsService) AddTeamMembership(ctx context.Context, team int, user string, opt *OrganizationAddTeamMembershipOptions) (*Membership, *Response, error) { - u := fmt.Sprintf("teams/%v/memberships/%v", team, user) - req, err := s.client.NewRequest("PUT", u, opt) - if err != nil { - return nil, nil, err - } - - t := new(Membership) - resp, err := s.client.Do(ctx, req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil -} - -// RemoveTeamMembership removes a user from a team. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-membership -func (s *OrganizationsService) RemoveTeamMembership(ctx context.Context, team int, user string) (*Response, error) { - u := fmt.Sprintf("teams/%v/memberships/%v", team, user) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// ListPendingTeamInvitations get pending invitaion list in team. -// Warning: The API may change without advance notice during the preview period. -// Preview features are not supported for production use. -// -// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations -func (s *OrganizationsService) ListPendingTeamInvitations(ctx context.Context, team int, opt *ListOptions) ([]*Invitation, *Response, error) { - u := fmt.Sprintf("teams/%v/invitations", team) - u, err := addOptions(u, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var pendingInvitations []*Invitation - resp, err := s.client.Do(ctx, req, &pendingInvitations) - if err != nil { - return nil, resp, err - } - - return pendingInvitations, resp, nil -} diff --git a/vendor/github.com/google/go-github/github/orgs_teams_test.go b/vendor/github.com/google/go-github/github/orgs_teams_test.go deleted file mode 100644 index ff1101dc5..000000000 --- a/vendor/github.com/google/go-github/github/orgs_teams_test.go +++ /dev/null @@ -1,581 +0,0 @@ -// Copyright 2013 The go-github AUTHORS. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package github - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "reflect" - "testing" - "time" -) - -func TestOrganizationsService_ListTeams(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{"page": "2"}) - fmt.Fprint(w, `[{"id":1}]`) - }) - - opt := &ListOptions{Page: 2} - teams, _, err := client.Organizations.ListTeams(context.Background(), "o", opt) - if err != nil { - t.Errorf("Organizations.ListTeams returned error: %v", err) - } - - want := []*Team{{ID: Int(1)}} - if !reflect.DeepEqual(teams, want) { - t.Errorf("Organizations.ListTeams returned %+v, want %+v", teams, want) - } -} - -func TestOrganizationsService_ListTeams_invalidOrg(t *testing.T) { - _, _, err := client.Organizations.ListTeams(context.Background(), "%", nil) - testURLParseError(t, err) -} - -func TestOrganizationsService_GetTeam(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com"}`) - }) - - team, _, err := client.Organizations.GetTeam(context.Background(), 1) - if err != nil { - t.Errorf("Organizations.GetTeam returned error: %v", err) - } - - want := &Team{ID: Int(1), Name: String("n"), Description: String("d"), URL: String("u"), Slug: String("s"), Permission: String("p"), LDAPDN: String("cn=n,ou=groups,dc=example,dc=com")} - if !reflect.DeepEqual(team, want) { - t.Errorf("Organizations.GetTeam returned %+v, want %+v", team, want) - } -} - -func TestOrganizationsService_CreateTeam(t *testing.T) { - setup() - defer teardown() - - input := &Team{Name: String("n"), Privacy: String("closed")} - - mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { - v := new(Team) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - - fmt.Fprint(w, `{"id":1}`) - }) - - team, _, err := client.Organizations.CreateTeam(context.Background(), "o", input) - if err != nil { - t.Errorf("Organizations.CreateTeam returned error: %v", err) - } - - want := &Team{ID: Int(1)} - if !reflect.DeepEqual(team, want) { - t.Errorf("Organizations.CreateTeam returned %+v, want %+v", team, want) - } -} - -func TestOrganizationsService_CreateTeam_invalidOrg(t *testing.T) { - _, _, err := client.Organizations.CreateTeam(context.Background(), "%", nil) - testURLParseError(t, err) -} - -func TestOrganizationsService_EditTeam(t *testing.T) { - setup() - defer teardown() - - input := &Team{Name: String("n"), Privacy: String("closed")} - - mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { - v := new(Team) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "PATCH") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - - fmt.Fprint(w, `{"id":1}`) - }) - - team, _, err := client.Organizations.EditTeam(context.Background(), 1, input) - if err != nil { - t.Errorf("Organizations.EditTeam returned error: %v", err) - } - - want := &Team{ID: Int(1)} - if !reflect.DeepEqual(team, want) { - t.Errorf("Organizations.EditTeam returned %+v, want %+v", team, want) - } -} - -func TestOrganizationsService_DeleteTeam(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - }) - - _, err := client.Organizations.DeleteTeam(context.Background(), 1) - if err != nil { - t.Errorf("Organizations.DeleteTeam returned error: %v", err) - } -} - -func TestOrganizationsService_ListTeamMembers(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{"role": "member", "page": "2"}) - fmt.Fprint(w, `[{"id":1}]`) - }) - - opt := &OrganizationListTeamMembersOptions{Role: "member", ListOptions: ListOptions{Page: 2}} - members, _, err := client.Organizations.ListTeamMembers(context.Background(), 1, opt) - if err != nil { - t.Errorf("Organizations.ListTeamMembers returned error: %v", err) - } - - want := []*User{{ID: Int(1)}} - if !reflect.DeepEqual(members, want) { - t.Errorf("Organizations.ListTeamMembers returned %+v, want %+v", members, want) - } -} - -func TestOrganizationsService_IsTeamMember_true(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - }) - - member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u") - if err != nil { - t.Errorf("Organizations.IsTeamMember returned error: %v", err) - } - if want := true; member != want { - t.Errorf("Organizations.IsTeamMember returned %+v, want %+v", member, want) - } -} - -// ensure that a 404 response is interpreted as "false" and not an error -func TestOrganizationsService_IsTeamMember_false(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - w.WriteHeader(http.StatusNotFound) - }) - - member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u") - if err != nil { - t.Errorf("Organizations.IsTeamMember returned error: %+v", err) - } - if want := false; member != want { - t.Errorf("Organizations.IsTeamMember returned %+v, want %+v", member, want) - } -} - -// ensure that a 400 response is interpreted as an actual error, and not simply -// as "false" like the above case of a 404 -func TestOrganizationsService_IsTeamMember_error(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - http.Error(w, "BadRequest", http.StatusBadRequest) - }) - - member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u") - if err == nil { - t.Errorf("Expected HTTP 400 response") - } - if want := false; member != want { - t.Errorf("Organizations.IsTeamMember returned %+v, want %+v", member, want) - } -} - -func TestOrganizationsService_IsTeamMember_invalidUser(t *testing.T) { - _, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "%") - testURLParseError(t, err) -} - -func TestOrganizationsService_PublicizeMembership(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PUT") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.PublicizeMembership(context.Background(), "o", "u") - if err != nil { - t.Errorf("Organizations.PublicizeMembership returned error: %v", err) - } -} - -func TestOrganizationsService_PublicizeMembership_invalidOrg(t *testing.T) { - _, err := client.Organizations.PublicizeMembership(context.Background(), "%", "u") - testURLParseError(t, err) -} - -func TestOrganizationsService_ConcealMembership(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.ConcealMembership(context.Background(), "o", "u") - if err != nil { - t.Errorf("Organizations.ConcealMembership returned error: %v", err) - } -} - -func TestOrganizationsService_ConcealMembership_invalidOrg(t *testing.T) { - _, err := client.Organizations.ConcealMembership(context.Background(), "%", "u") - testURLParseError(t, err) -} - -func TestOrganizationsService_ListTeamRepos(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeTopicsPreview) - testFormValues(t, r, values{"page": "2"}) - fmt.Fprint(w, `[{"id":1}]`) - }) - - opt := &ListOptions{Page: 2} - members, _, err := client.Organizations.ListTeamRepos(context.Background(), 1, opt) - if err != nil { - t.Errorf("Organizations.ListTeamRepos returned error: %v", err) - } - - want := []*Repository{{ID: Int(1)}} - if !reflect.DeepEqual(members, want) { - t.Errorf("Organizations.ListTeamRepos returned %+v, want %+v", members, want) - } -} - -func TestOrganizationsService_IsTeamRepo_true(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeOrgPermissionRepo) - fmt.Fprint(w, `{"id":1}`) - }) - - repo, _, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r") - if err != nil { - t.Errorf("Organizations.IsTeamRepo returned error: %v", err) - } - - want := &Repository{ID: Int(1)} - if !reflect.DeepEqual(repo, want) { - t.Errorf("Organizations.IsTeamRepo returned %+v, want %+v", repo, want) - } -} - -func TestOrganizationsService_IsTeamRepo_false(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - w.WriteHeader(http.StatusNotFound) - }) - - repo, resp, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r") - if err == nil { - t.Errorf("Expected HTTP 404 response") - } - if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want { - t.Errorf("Organizations.IsTeamRepo returned status %d, want %d", got, want) - } - if repo != nil { - t.Errorf("Organizations.IsTeamRepo returned %+v, want nil", repo) - } -} - -func TestOrganizationsService_IsTeamRepo_error(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - http.Error(w, "BadRequest", http.StatusBadRequest) - }) - - repo, resp, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r") - if err == nil { - t.Errorf("Expected HTTP 400 response") - } - if got, want := resp.Response.StatusCode, http.StatusBadRequest; got != want { - t.Errorf("Organizations.IsTeamRepo returned status %d, want %d", got, want) - } - if repo != nil { - t.Errorf("Organizations.IsTeamRepo returned %+v, want nil", repo) - } -} - -func TestOrganizationsService_IsTeamRepo_invalidOwner(t *testing.T) { - _, _, err := client.Organizations.IsTeamRepo(context.Background(), 1, "%", "r") - testURLParseError(t, err) -} - -func TestOrganizationsService_AddTeamRepo(t *testing.T) { - setup() - defer teardown() - - opt := &OrganizationAddTeamRepoOptions{Permission: "admin"} - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - v := new(OrganizationAddTeamRepoOptions) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "PUT") - if !reflect.DeepEqual(v, opt) { - t.Errorf("Request body = %+v, want %+v", v, opt) - } - - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "o", "r", opt) - if err != nil { - t.Errorf("Organizations.AddTeamRepo returned error: %v", err) - } -} - -func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PUT") - w.WriteHeader(http.StatusUnprocessableEntity) - }) - - _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "o", "r", nil) - if err == nil { - t.Errorf("Expcted error to be returned") - } -} - -func TestOrganizationsService_AddTeamRepo_invalidOwner(t *testing.T) { - _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "%", "r", nil) - testURLParseError(t, err) -} - -func TestOrganizationsService_RemoveTeamRepo(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.RemoveTeamRepo(context.Background(), 1, "o", "r") - if err != nil { - t.Errorf("Organizations.RemoveTeamRepo returned error: %v", err) - } -} - -func TestOrganizationsService_RemoveTeamRepo_invalidOwner(t *testing.T) { - _, err := client.Organizations.RemoveTeamRepo(context.Background(), 1, "%", "r") - testURLParseError(t, err) -} - -func TestOrganizationsService_GetTeamMembership(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{"url":"u", "state":"active"}`) - }) - - membership, _, err := client.Organizations.GetTeamMembership(context.Background(), 1, "u") - if err != nil { - t.Errorf("Organizations.GetTeamMembership returned error: %v", err) - } - - want := &Membership{URL: String("u"), State: String("active")} - if !reflect.DeepEqual(membership, want) { - t.Errorf("Organizations.GetTeamMembership returned %+v, want %+v", membership, want) - } -} - -func TestOrganizationsService_AddTeamMembership(t *testing.T) { - setup() - defer teardown() - - opt := &OrganizationAddTeamMembershipOptions{Role: "maintainer"} - - mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { - v := new(OrganizationAddTeamMembershipOptions) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "PUT") - if !reflect.DeepEqual(v, opt) { - t.Errorf("Request body = %+v, want %+v", v, opt) - } - - fmt.Fprint(w, `{"url":"u", "state":"pending"}`) - }) - - membership, _, err := client.Organizations.AddTeamMembership(context.Background(), 1, "u", opt) - if err != nil { - t.Errorf("Organizations.AddTeamMembership returned error: %v", err) - } - - want := &Membership{URL: String("u"), State: String("pending")} - if !reflect.DeepEqual(membership, want) { - t.Errorf("Organizations.AddTeamMembership returned %+v, want %+v", membership, want) - } -} - -func TestOrganizationsService_RemoveTeamMembership(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.RemoveTeamMembership(context.Background(), 1, "u") - if err != nil { - t.Errorf("Organizations.RemoveTeamMembership returned error: %v", err) - } -} - -func TestOrganizationsService_ListUserTeams(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/user/teams", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{"page": "1"}) - fmt.Fprint(w, `[{"id":1}]`) - }) - - opt := &ListOptions{Page: 1} - teams, _, err := client.Organizations.ListUserTeams(context.Background(), opt) - if err != nil { - t.Errorf("Organizations.ListUserTeams returned error: %v", err) - } - - want := []*Team{{ID: Int(1)}} - if !reflect.DeepEqual(teams, want) { - t.Errorf("Organizations.ListUserTeams returned %+v, want %+v", teams, want) - } -} - -func TestOrganizationsService_ListPendingTeamInvitations(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/invitations", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{"page": "1"}) - fmt.Fprint(w, `[ - { - "id": 1, - "login": "monalisa", - "email": "octocat@github.com", - "role": "direct_member", - "created_at": "2017-01-21T00:00:00Z", - "inviter": { - "login": "other_user", - "id": 1, - "avatar_url": "https://github.com/images/error/other_user_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/other_user", - "html_url": "https://github.com/other_user", - "followers_url": "https://api.github.com/users/other_user/followers", - "following_url": "https://api.github.com/users/other_user/following/other_user", - "gists_url": "https://api.github.com/users/other_user/gists/gist_id", - "starred_url": "https://api.github.com/users/other_user/starred/owner/repo", - "subscriptions_url": "https://api.github.com/users/other_user/subscriptions", - "organizations_url": "https://api.github.com/users/other_user/orgs", - "repos_url": "https://api.github.com/users/other_user/repos", - "events_url": "https://api.github.com/users/other_user/events/privacy", - "received_events_url": "https://api.github.com/users/other_user/received_events/privacy", - "type": "User", - "site_admin": false - } - } - ]`) - }) - - opt := &ListOptions{Page: 1} - invitations, _, err := client.Organizations.ListPendingTeamInvitations(context.Background(), 1, opt) - if err != nil { - t.Errorf("Organizations.ListPendingTeamInvitations returned error: %v", err) - } - - createdAt := time.Date(2017, 01, 21, 0, 0, 0, 0, time.UTC) - want := []*Invitation{ - { - ID: Int(1), - Login: String("monalisa"), - Email: String("octocat@github.com"), - Role: String("direct_member"), - CreatedAt: &createdAt, - Inviter: &User{ - Login: String("other_user"), - ID: Int(1), - AvatarURL: String("https://github.com/images/error/other_user_happy.gif"), - GravatarID: String(""), - URL: String("https://api.github.com/users/other_user"), - HTMLURL: String("https://github.com/other_user"), - FollowersURL: String("https://api.github.com/users/other_user/followers"), - FollowingURL: String("https://api.github.com/users/other_user/following/other_user"), - GistsURL: String("https://api.github.com/users/other_user/gists/gist_id"), - StarredURL: String("https://api.github.com/users/other_user/starred/owner/repo"), - SubscriptionsURL: String("https://api.github.com/users/other_user/subscriptions"), - OrganizationsURL: String("https://api.github.com/users/other_user/orgs"), - ReposURL: String("https://api.github.com/users/other_user/repos"), - EventsURL: String("https://api.github.com/users/other_user/events/privacy"), - ReceivedEventsURL: String("https://api.github.com/users/other_user/received_events/privacy"), - Type: String("User"), - SiteAdmin: Bool(false), - }, - }} - - if !reflect.DeepEqual(invitations, want) { - t.Errorf("Organizations.ListPendingTeamInvitations returned %+v, want %+v", invitations, want) - } -} diff --git a/vendor/github.com/google/go-github/github/orgs_test.go b/vendor/github.com/google/go-github/github/orgs_test.go index 6e227e8e5..9fe484dbb 100644 --- a/vendor/github.com/google/go-github/github/orgs_test.go +++ b/vendor/github.com/google/go-github/github/orgs_test.go @@ -15,10 +15,10 @@ import ( ) func TestOrganizationsService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - since := 1342004 + since := int64(1342004) mux.HandleFunc("/organizations", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"since": "1342004"}) @@ -31,14 +31,14 @@ func TestOrganizationsService_ListAll(t *testing.T) { t.Errorf("Organizations.ListAll returned error: %v", err) } - want := []*Organization{{ID: Int(4314092)}} + want := []*Organization{{ID: Int64(4314092)}} if !reflect.DeepEqual(orgs, want) { t.Errorf("Organizations.ListAll returned %+v, want %+v", orgs, want) } } func TestOrganizationsService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -51,14 +51,14 @@ func TestOrganizationsService_List_authenticatedUser(t *testing.T) { t.Errorf("Organizations.List returned error: %v", err) } - want := []*Organization{{ID: Int(1)}, {ID: Int(2)}} + want := []*Organization{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(orgs, want) { t.Errorf("Organizations.List returned %+v, want %+v", orgs, want) } } func TestOrganizationsService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -73,19 +73,22 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) { t.Errorf("Organizations.List returned error: %v", err) } - want := []*Organization{{ID: Int(1)}, {ID: Int(2)}} + want := []*Organization{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(orgs, want) { t.Errorf("Organizations.List returned %+v, want %+v", orgs, want) } } func TestOrganizationsService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) { @@ -98,19 +101,22 @@ func TestOrganizationsService_Get(t *testing.T) { t.Errorf("Organizations.Get returned error: %v", err) } - want := &Organization{ID: Int(1), Login: String("l"), URL: String("u"), AvatarURL: String("a"), Location: String("l")} + want := &Organization{ID: Int64(1), Login: String("l"), URL: String("u"), AvatarURL: String("a"), Location: String("l")} if !reflect.DeepEqual(org, want) { t.Errorf("Organizations.Get returned %+v, want %+v", org, want) } } func TestOrganizationsService_Get_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.Get(context.Background(), "%") testURLParseError(t, err) } func TestOrganizationsService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/organizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -123,14 +129,14 @@ func TestOrganizationsService_GetByID(t *testing.T) { t.Fatalf("Organizations.GetByID returned error: %v", err) } - want := &Organization{ID: Int(1), Login: String("l"), URL: String("u"), AvatarURL: String("a"), Location: String("l")} + want := &Organization{ID: Int64(1), Login: String("l"), URL: String("u"), AvatarURL: String("a"), Location: String("l")} if !reflect.DeepEqual(org, want) { t.Errorf("Organizations.GetByID returned %+v, want %+v", org, want) } } func TestOrganizationsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Organization{Login: String("l")} @@ -152,13 +158,16 @@ func TestOrganizationsService_Edit(t *testing.T) { t.Errorf("Organizations.Edit returned error: %v", err) } - want := &Organization{ID: Int(1)} + want := &Organization{ID: Int64(1)} if !reflect.DeepEqual(org, want) { t.Errorf("Organizations.Edit returned %+v, want %+v", org, want) } } func TestOrganizationsService_Edit_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.Edit(context.Background(), "%", nil) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/orgs_users_blocking_test.go b/vendor/github.com/google/go-github/github/orgs_users_blocking_test.go index 53be507ef..5d38cc44e 100644 --- a/vendor/github.com/google/go-github/github/orgs_users_blocking_test.go +++ b/vendor/github.com/google/go-github/github/orgs_users_blocking_test.go @@ -14,7 +14,7 @@ import ( ) func TestOrganizationsService_ListBlockedUsers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestOrganizationsService_ListBlockedUsers(t *testing.T) { } func TestOrganizationsService_IsBlocked(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestOrganizationsService_IsBlocked(t *testing.T) { } func TestOrganizationsService_BlockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -74,7 +74,7 @@ func TestOrganizationsService_BlockUser(t *testing.T) { } func TestOrganizationsService_UnblockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/projects.go b/vendor/github.com/google/go-github/github/projects.go index 89685c9d7..210e3b5c3 100644 --- a/vendor/github.com/google/go-github/github/projects.go +++ b/vendor/github.com/google/go-github/github/projects.go @@ -18,14 +18,18 @@ type ProjectsService service // Project represents a GitHub Project. type Project struct { - ID *int `json:"id,omitempty"` - URL *string `json:"url,omitempty"` - OwnerURL *string `json:"owner_url,omitempty"` - Name *string `json:"name,omitempty"` - Body *string `json:"body,omitempty"` - Number *int `json:"number,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` + ID *int64 `json:"id,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + ColumnsURL *string `json:"columns_url,omitempty"` + OwnerURL *string `json:"owner_url,omitempty"` + Name *string `json:"name,omitempty"` + Body *string `json:"body,omitempty"` + Number *int `json:"number,omitempty"` + State *string `json:"state,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` // The User object that generated the project. Creator *User `json:"creator,omitempty"` @@ -38,14 +42,14 @@ func (p Project) String() string { // GetProject gets a GitHub Project for a repo. // // GitHub API docs: https://developer.github.com/v3/projects/#get-a-project -func (s *ProjectsService) GetProject(ctx context.Context, id int) (*Project, *Response, error) { +func (s *ProjectsService) GetProject(ctx context.Context, id int64) (*Project, *Response, error) { u := fmt.Sprintf("projects/%v", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) project := &Project{} @@ -62,22 +66,37 @@ func (s *ProjectsService) GetProject(ctx context.Context, id int) (*Project, *Re // ProjectsService.UpdateProject methods. type ProjectOptions struct { // The name of the project. (Required for creation; optional for update.) - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // The body of the project. (Optional.) - Body string `json:"body,omitempty"` + Body *string `json:"body,omitempty"` + + // The following field(s) are only applicable for update. + // They should be left with zero values for creation. + + // State of the project. Either "open" or "closed". (Optional.) + State *string `json:"state,omitempty"` + // The permission level that all members of the project's organization + // will have on this project. + // Setting the organization permission is only available + // for organization projects. (Optional.) + OrganizationPermission *string `json:"organization_permission,omitempty"` + // Sets visibility of the project within the organization. + // Setting visibility is only available + // for organization projects.(Optional.) + Public *bool `json:"public,omitempty"` } // UpdateProject updates a repository project. // // GitHub API docs: https://developer.github.com/v3/projects/#update-a-project -func (s *ProjectsService) UpdateProject(ctx context.Context, id int, opt *ProjectOptions) (*Project, *Response, error) { +func (s *ProjectsService) UpdateProject(ctx context.Context, id int64, opt *ProjectOptions) (*Project, *Response, error) { u := fmt.Sprintf("projects/%v", id) req, err := s.client.NewRequest("PATCH", u, opt) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) project := &Project{} @@ -92,7 +111,7 @@ func (s *ProjectsService) UpdateProject(ctx context.Context, id int, opt *Projec // DeleteProject deletes a GitHub Project from a repository. // // GitHub API docs: https://developer.github.com/v3/projects/#delete-a-project -func (s *ProjectsService) DeleteProject(ctx context.Context, id int) (*Response, error) { +func (s *ProjectsService) DeleteProject(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("projects/%v", id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -109,17 +128,20 @@ func (s *ProjectsService) DeleteProject(ctx context.Context, id int) (*Response, // // GitHub API docs: https://developer.github.com/v3/repos/projects/ type ProjectColumn struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Name *string `json:"name,omitempty"` + URL *string `json:"url,omitempty"` ProjectURL *string `json:"project_url,omitempty"` + CardsURL *string `json:"cards_url,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` } // ListProjectColumns lists the columns of a GitHub Project for a repo. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#list-project-columns -func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int, opt *ListOptions) ([]*ProjectColumn, *Response, error) { +func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int64, opt *ListOptions) ([]*ProjectColumn, *Response, error) { u := fmt.Sprintf("projects/%v/columns", projectID) u, err := addOptions(u, opt) if err != nil { @@ -131,7 +153,7 @@ func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) columns := []*ProjectColumn{} @@ -146,14 +168,14 @@ func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int, // GetProjectColumn gets a column of a GitHub Project for a repo. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#get-a-project-column -func (s *ProjectsService) GetProjectColumn(ctx context.Context, id int) (*ProjectColumn, *Response, error) { +func (s *ProjectsService) GetProjectColumn(ctx context.Context, id int64) (*ProjectColumn, *Response, error) { u := fmt.Sprintf("projects/columns/%v", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) column := &ProjectColumn{} @@ -176,14 +198,14 @@ type ProjectColumnOptions struct { // CreateProjectColumn creates a column for the specified (by number) project. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#create-a-project-column -func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) { +func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int64, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) { u := fmt.Sprintf("projects/%v/columns", projectID) req, err := s.client.NewRequest("POST", u, opt) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) column := &ProjectColumn{} @@ -198,14 +220,14 @@ func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int // UpdateProjectColumn updates a column of a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#update-a-project-column -func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) { +func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int64, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) { u := fmt.Sprintf("projects/columns/%v", columnID) req, err := s.client.NewRequest("PATCH", u, opt) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) column := &ProjectColumn{} @@ -220,7 +242,7 @@ func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int, // DeleteProjectColumn deletes a column from a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#delete-a-project-column -func (s *ProjectsService) DeleteProjectColumn(ctx context.Context, columnID int) (*Response, error) { +func (s *ProjectsService) DeleteProjectColumn(ctx context.Context, columnID int64) (*Response, error) { u := fmt.Sprintf("projects/columns/%v", columnID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -244,7 +266,7 @@ type ProjectColumnMoveOptions struct { // MoveProjectColumn moves a column within a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/columns/#move-a-project-column -func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int, opt *ProjectColumnMoveOptions) (*Response, error) { +func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int64, opt *ProjectColumnMoveOptions) (*Response, error) { u := fmt.Sprintf("projects/columns/%v/moves", columnID) req, err := s.client.NewRequest("POST", u, opt) if err != nil { @@ -264,20 +286,32 @@ type ProjectCard struct { URL *string `json:"url,omitempty"` ColumnURL *string `json:"column_url,omitempty"` ContentURL *string `json:"content_url,omitempty"` - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Note *string `json:"note,omitempty"` Creator *User `json:"creator,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Archived *bool `json:"archived,omitempty"` // The following fields are only populated by Webhook events. - ColumnID *int `json:"column_id,omitempty"` + ColumnID *int64 `json:"column_id,omitempty"` +} + +// ProjectCardListOptions specifies the optional parameters to the +// ProjectsService.ListProjectCards method. +type ProjectCardListOptions struct { + // ArchivedState is used to list all, archived, or not_archived project cards. + // Defaults to not_archived when you omit this parameter. + ArchivedState *string `url:"archived_state,omitempty"` + + ListOptions } // ListProjectCards lists the cards in a column of a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#list-project-cards -func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int, opt *ListOptions) ([]*ProjectCard, *Response, error) { +func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int64, opt *ProjectCardListOptions) ([]*ProjectCard, *Response, error) { u := fmt.Sprintf("projects/columns/%v/cards", columnID) u, err := addOptions(u, opt) if err != nil { @@ -289,7 +323,7 @@ func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int, op return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) cards := []*ProjectCard{} @@ -304,14 +338,14 @@ func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int, op // GetProjectCard gets a card in a column of a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#get-a-project-card -func (s *ProjectsService) GetProjectCard(ctx context.Context, columnID int) (*ProjectCard, *Response, error) { +func (s *ProjectsService) GetProjectCard(ctx context.Context, columnID int64) (*ProjectCard, *Response, error) { u := fmt.Sprintf("projects/columns/cards/%v", columnID) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) card := &ProjectCard{} @@ -331,22 +365,25 @@ type ProjectCardOptions struct { Note string `json:"note,omitempty"` // The ID (not Number) of the Issue to associate with this card. // Note and ContentID are mutually exclusive. - ContentID int `json:"content_id,omitempty"` - // The type of content to associate with this card. Possible values are: "Issue". + ContentID int64 `json:"content_id,omitempty"` + // The type of content to associate with this card. Possible values are: "Issue" and "PullRequest". ContentType string `json:"content_type,omitempty"` + // Use true to archive a project card. + // Specify false if you need to restore a previously archived project card. + Archived *bool `json:"archived,omitempty"` } // CreateProjectCard creates a card in the specified column of a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#create-a-project-card -func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) { +func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int64, opt *ProjectCardOptions) (*ProjectCard, *Response, error) { u := fmt.Sprintf("projects/columns/%v/cards", columnID) req, err := s.client.NewRequest("POST", u, opt) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) card := &ProjectCard{} @@ -361,14 +398,14 @@ func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int, o // UpdateProjectCard updates a card of a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#update-a-project-card -func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) { +func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int64, opt *ProjectCardOptions) (*ProjectCard, *Response, error) { u := fmt.Sprintf("projects/columns/cards/%v", cardID) req, err := s.client.NewRequest("PATCH", u, opt) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) card := &ProjectCard{} @@ -383,7 +420,7 @@ func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int, opt // DeleteProjectCard deletes a card from a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#delete-a-project-card -func (s *ProjectsService) DeleteProjectCard(ctx context.Context, cardID int) (*Response, error) { +func (s *ProjectsService) DeleteProjectCard(ctx context.Context, cardID int64) (*Response, error) { u := fmt.Sprintf("projects/columns/cards/%v", cardID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -405,13 +442,13 @@ type ProjectCardMoveOptions struct { // ColumnID is the ID of a column in the same project. Note that ColumnID // is required when using Position "after:" when that card is in // another column; otherwise it is optional. - ColumnID int `json:"column_id,omitempty"` + ColumnID int64 `json:"column_id,omitempty"` } // MoveProjectCard moves a card within a GitHub Project. // // GitHub API docs: https://developer.github.com/v3/projects/cards/#move-a-project-card -func (s *ProjectsService) MoveProjectCard(ctx context.Context, cardID int, opt *ProjectCardMoveOptions) (*Response, error) { +func (s *ProjectsService) MoveProjectCard(ctx context.Context, cardID int64, opt *ProjectCardMoveOptions) (*Response, error) { u := fmt.Sprintf("projects/columns/cards/%v/moves", cardID) req, err := s.client.NewRequest("POST", u, opt) if err != nil { diff --git a/vendor/github.com/google/go-github/github/projects_test.go b/vendor/github.com/google/go-github/github/projects_test.go index 1045ca9be..9f12272a7 100644 --- a/vendor/github.com/google/go-github/github/projects_test.go +++ b/vendor/github.com/google/go-github/github/projects_test.go @@ -11,14 +11,22 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" ) func TestProjectsService_UpdateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &ProjectOptions{Name: "Project Name", Body: "Project body."} + input := &ProjectOptions{ + Name: String("Project Name"), + Body: String("Project body."), + State: String("open"), + Public: Bool(true), + + OrganizationPermission: String("read"), + } mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") @@ -38,14 +46,14 @@ func TestProjectsService_UpdateProject(t *testing.T) { t.Errorf("Projects.UpdateProject returned error: %v", err) } - want := &Project{ID: Int(1)} + want := &Project{ID: Int64(1)} if !reflect.DeepEqual(project, want) { t.Errorf("Projects.UpdateProject returned %+v, want %+v", project, want) } } func TestProjectsService_GetProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) { @@ -59,14 +67,14 @@ func TestProjectsService_GetProject(t *testing.T) { t.Errorf("Projects.GetProject returned error: %v", err) } - want := &Project{ID: Int(1)} + want := &Project{ID: Int64(1)} if !reflect.DeepEqual(project, want) { t.Errorf("Projects.GetProject returned %+v, want %+v", project, want) } } func TestProjectsService_DeleteProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) { @@ -81,12 +89,13 @@ func TestProjectsService_DeleteProject(t *testing.T) { } func TestProjectsService_ListProjectColumns(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeProjectsPreview} mux.HandleFunc("/projects/1/columns", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProjectsPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) @@ -97,14 +106,14 @@ func TestProjectsService_ListProjectColumns(t *testing.T) { t.Errorf("Projects.ListProjectColumns returned error: %v", err) } - want := []*ProjectColumn{{ID: Int(1)}} + want := []*ProjectColumn{{ID: Int64(1)}} if !reflect.DeepEqual(columns, want) { t.Errorf("Projects.ListProjectColumns returned %+v, want %+v", columns, want) } } func TestProjectsService_GetProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1", func(w http.ResponseWriter, r *http.Request) { @@ -118,14 +127,14 @@ func TestProjectsService_GetProjectColumn(t *testing.T) { t.Errorf("Projects.GetProjectColumn returned error: %v", err) } - want := &ProjectColumn{ID: Int(1)} + want := &ProjectColumn{ID: Int64(1)} if !reflect.DeepEqual(column, want) { t.Errorf("Projects.GetProjectColumn returned %+v, want %+v", column, want) } } func TestProjectsService_CreateProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnOptions{Name: "Column Name"} @@ -148,14 +157,14 @@ func TestProjectsService_CreateProjectColumn(t *testing.T) { t.Errorf("Projects.CreateProjectColumn returned error: %v", err) } - want := &ProjectColumn{ID: Int(1)} + want := &ProjectColumn{ID: Int64(1)} if !reflect.DeepEqual(column, want) { t.Errorf("Projects.CreateProjectColumn returned %+v, want %+v", column, want) } } func TestProjectsService_UpdateProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnOptions{Name: "Column Name"} @@ -178,14 +187,14 @@ func TestProjectsService_UpdateProjectColumn(t *testing.T) { t.Errorf("Projects.UpdateProjectColumn returned error: %v", err) } - want := &ProjectColumn{ID: Int(1)} + want := &ProjectColumn{ID: Int64(1)} if !reflect.DeepEqual(column, want) { t.Errorf("Projects.UpdateProjectColumn returned %+v, want %+v", column, want) } } func TestProjectsService_DeleteProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1", func(w http.ResponseWriter, r *http.Request) { @@ -200,7 +209,7 @@ func TestProjectsService_DeleteProjectColumn(t *testing.T) { } func TestProjectsService_MoveProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnMoveOptions{Position: "after:12345"} @@ -223,30 +232,34 @@ func TestProjectsService_MoveProjectColumn(t *testing.T) { } func TestProjectsService_ListProjectCards(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1/cards", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", mediaTypeProjectsPreview) - testFormValues(t, r, values{"page": "2"}) + testFormValues(t, r, values{ + "archived_state": "all", + "page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) - opt := &ListOptions{Page: 2} + opt := &ProjectCardListOptions{ + ArchivedState: String("all"), + ListOptions: ListOptions{Page: 2}} cards, _, err := client.Projects.ListProjectCards(context.Background(), 1, opt) if err != nil { t.Errorf("Projects.ListProjectCards returned error: %v", err) } - want := []*ProjectCard{{ID: Int(1)}} + want := []*ProjectCard{{ID: Int64(1)}} if !reflect.DeepEqual(cards, want) { t.Errorf("Projects.ListProjectCards returned %+v, want %+v", cards, want) } } func TestProjectsService_GetProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/cards/1", func(w http.ResponseWriter, r *http.Request) { @@ -260,14 +273,14 @@ func TestProjectsService_GetProjectCard(t *testing.T) { t.Errorf("Projects.GetProjectCard returned error: %v", err) } - want := &ProjectCard{ID: Int(1)} + want := &ProjectCard{ID: Int64(1)} if !reflect.DeepEqual(card, want) { t.Errorf("Projects.GetProjectCard returned %+v, want %+v", card, want) } } func TestProjectsService_CreateProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardOptions{ @@ -293,14 +306,14 @@ func TestProjectsService_CreateProjectCard(t *testing.T) { t.Errorf("Projects.CreateProjectCard returned error: %v", err) } - want := &ProjectCard{ID: Int(1)} + want := &ProjectCard{ID: Int64(1)} if !reflect.DeepEqual(card, want) { t.Errorf("Projects.CreateProjectCard returned %+v, want %+v", card, want) } } func TestProjectsService_UpdateProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardOptions{ @@ -318,7 +331,7 @@ func TestProjectsService_UpdateProjectCard(t *testing.T) { t.Errorf("Request body = %+v, want %+v", v, input) } - fmt.Fprint(w, `{"id":1}`) + fmt.Fprint(w, `{"id":1, "archived":false}`) }) card, _, err := client.Projects.UpdateProjectCard(context.Background(), 1, input) @@ -326,14 +339,14 @@ func TestProjectsService_UpdateProjectCard(t *testing.T) { t.Errorf("Projects.UpdateProjectCard returned error: %v", err) } - want := &ProjectCard{ID: Int(1)} + want := &ProjectCard{ID: Int64(1), Archived: Bool(false)} if !reflect.DeepEqual(card, want) { t.Errorf("Projects.UpdateProjectCard returned %+v, want %+v", card, want) } } func TestProjectsService_DeleteProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/cards/1", func(w http.ResponseWriter, r *http.Request) { @@ -348,7 +361,7 @@ func TestProjectsService_DeleteProjectCard(t *testing.T) { } func TestProjectsService_MoveProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardMoveOptions{Position: "after:12345"} diff --git a/vendor/github.com/google/go-github/github/pulls.go b/vendor/github.com/google/go-github/github/pulls.go index bc46081fc..602611421 100644 --- a/vendor/github.com/google/go-github/github/pulls.go +++ b/vendor/github.com/google/go-github/github/pulls.go @@ -9,6 +9,7 @@ import ( "bytes" "context" "fmt" + "strings" "time" ) @@ -20,7 +21,7 @@ type PullRequestsService service // PullRequest represents a GitHub pull request on a repository. type PullRequest struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Number *int `json:"number,omitempty"` State *string `json:"state,omitempty"` Title *string `json:"title,omitempty"` @@ -29,9 +30,11 @@ type PullRequest struct { UpdatedAt *time.Time `json:"updated_at,omitempty"` ClosedAt *time.Time `json:"closed_at,omitempty"` MergedAt *time.Time `json:"merged_at,omitempty"` + Labels []*Label `json:"labels,omitempty"` User *User `json:"user,omitempty"` Merged *bool `json:"merged,omitempty"` Mergeable *bool `json:"mergeable,omitempty"` + MergeableState *string `json:"mergeable_state,omitempty"` MergedBy *User `json:"merged_by,omitempty"` MergeCommitSHA *string `json:"merge_commit_sha,omitempty"` Comments *int `json:"comments,omitempty"` @@ -45,21 +48,52 @@ type PullRequest struct { StatusesURL *string `json:"statuses_url,omitempty"` DiffURL *string `json:"diff_url,omitempty"` PatchURL *string `json:"patch_url,omitempty"` + CommitsURL *string `json:"commits_url,omitempty"` + CommentsURL *string `json:"comments_url,omitempty"` ReviewCommentsURL *string `json:"review_comments_url,omitempty"` ReviewCommentURL *string `json:"review_comment_url,omitempty"` Assignee *User `json:"assignee,omitempty"` Assignees []*User `json:"assignees,omitempty"` Milestone *Milestone `json:"milestone,omitempty"` MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"` + AuthorAssociation *string `json:"author_association,omitempty"` + NodeID *string `json:"node_id,omitempty"` + RequestedReviewers []*User `json:"requested_reviewers,omitempty"` - Head *PullRequestBranch `json:"head,omitempty"` - Base *PullRequestBranch `json:"base,omitempty"` + // RequestedTeams is populated as part of the PullRequestEvent. + // See, https://developer.github.com/v3/activity/events/types/#pullrequestevent for an example. + RequestedTeams []*Team `json:"requested_teams,omitempty"` + + Links *PRLinks `json:"_links,omitempty"` + Head *PullRequestBranch `json:"head,omitempty"` + Base *PullRequestBranch `json:"base,omitempty"` + + // ActiveLockReason is populated only when LockReason is provided while locking the pull request. + // Possible values are: "off-topic", "too heated", "resolved", and "spam". + ActiveLockReason *string `json:"active_lock_reason,omitempty"` } func (p PullRequest) String() string { return Stringify(p) } +// PRLink represents a single link object from Github pull request _links. +type PRLink struct { + HRef *string `json:"href,omitempty"` +} + +// PRLinks represents the "_links" object in a Github pull request. +type PRLinks struct { + Self *PRLink `json:"self,omitempty"` + HTML *PRLink `json:"html,omitempty"` + Issue *PRLink `json:"issue,omitempty"` + Comments *PRLink `json:"comments,omitempty"` + ReviewComments *PRLink `json:"review_comments,omitempty"` + ReviewComment *PRLink `json:"review_comment,omitempty"` + Commits *PRLink `json:"commits,omitempty"` + Statuses *PRLink `json:"statuses,omitempty"` +} + // PullRequestBranch represents a base or head branch in a GitHub pull request. type PullRequestBranch struct { Label *string `json:"label,omitempty"` @@ -73,7 +107,7 @@ type PullRequestBranch struct { // PullRequestsService.List method. type PullRequestListOptions struct { // State filters pull requests based on their state. Possible values are: - // open, closed. Default is "open". + // open, closed, all. Default is "open". State string `url:"state,omitempty"` // Head filters pull requests by head user and branch name in the format of: @@ -110,6 +144,10 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) + var pulls []*PullRequest resp, err := s.client.Do(ctx, req, &pulls) if err != nil { @@ -129,6 +167,10 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) + pull := new(PullRequest) resp, err := s.client.Do(ctx, req, pull) if err != nil { @@ -138,7 +180,7 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string return pull, resp, nil } -// GetRaw gets raw (diff or patch) format of a pull request. +// GetRaw gets a single pull request in raw (diff or patch) format. func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo string, number int, opt RawOptions) (string, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) req, err := s.client.NewRequest("GET", u, nil) @@ -155,13 +197,13 @@ func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo str return "", nil, fmt.Errorf("unsupported raw type %d", opt.Type) } - ret := new(bytes.Buffer) - resp, err := s.client.Do(ctx, req, ret) + var buf bytes.Buffer + resp, err := s.client.Do(ctx, req, &buf) if err != nil { return "", resp, err } - return ret.String(), resp, nil + return buf.String(), resp, nil } // NewPullRequest represents a new pull request to be created. @@ -184,6 +226,9 @@ func (s *PullRequestsService) Create(ctx context.Context, owner string, repo str return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) + p := new(PullRequest) resp, err := s.client.Do(ctx, req, p) if err != nil { @@ -230,6 +275,10 @@ func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo strin return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) + p := new(PullRequest) resp, err := s.client.Do(ctx, req, p) if err != nil { diff --git a/vendor/github.com/google/go-github/github/pulls_comments.go b/vendor/github.com/google/go-github/github/pulls_comments.go index bc0bc2d4a..f30677625 100644 --- a/vendor/github.com/google/go-github/github/pulls_comments.go +++ b/vendor/github.com/google/go-github/github/pulls_comments.go @@ -13,22 +13,26 @@ import ( // PullRequestComment represents a comment left on a pull request. type PullRequestComment struct { - ID *int `json:"id,omitempty"` - InReplyTo *int `json:"in_reply_to,omitempty"` - Body *string `json:"body,omitempty"` - Path *string `json:"path,omitempty"` - DiffHunk *string `json:"diff_hunk,omitempty"` - Position *int `json:"position,omitempty"` - OriginalPosition *int `json:"original_position,omitempty"` - CommitID *string `json:"commit_id,omitempty"` - OriginalCommitID *string `json:"original_commit_id,omitempty"` - User *User `json:"user,omitempty"` - Reactions *Reactions `json:"reactions,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - PullRequestURL *string `json:"pull_request_url,omitempty"` + ID *int64 `json:"id,omitempty"` + InReplyTo *int64 `json:"in_reply_to_id,omitempty"` + Body *string `json:"body,omitempty"` + Path *string `json:"path,omitempty"` + DiffHunk *string `json:"diff_hunk,omitempty"` + PullRequestReviewID *int64 `json:"pull_request_review_id,omitempty"` + Position *int `json:"position,omitempty"` + OriginalPosition *int `json:"original_position,omitempty"` + CommitID *string `json:"commit_id,omitempty"` + OriginalCommitID *string `json:"original_commit_id,omitempty"` + User *User `json:"user,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + // AuthorAssociation is the comment author's relationship to the pull request's repository. + // Possible values are "COLLABORATOR", "CONTRIBUTOR", "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR", "MEMBER", "OWNER", or "NONE". + AuthorAssociation *string `json:"author_association,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + PullRequestURL *string `json:"pull_request_url,omitempty"` } func (p PullRequestComment) String() string { @@ -87,8 +91,8 @@ func (s *PullRequestsService) ListComments(ctx context.Context, owner string, re // GetComment fetches the specified pull request comment. // // GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment -func (s *PullRequestsService) GetComment(ctx context.Context, owner string, repo string, number int) (*PullRequestComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) +func (s *PullRequestsService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*PullRequestComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -125,11 +129,38 @@ func (s *PullRequestsService) CreateComment(ctx context.Context, owner string, r return c, resp, nil } +// CreateCommentInReplyTo creates a new comment as a reply to an existing pull request comment. +// +// GitHub API docs: https://developer.github.com/v3/pulls/comments/#alternative-input +func (s *PullRequestsService) CreateCommentInReplyTo(ctx context.Context, owner string, repo string, number int, body string, commentID int64) (*PullRequestComment, *Response, error) { + comment := &struct { + Body string `json:"body,omitempty"` + InReplyTo int64 `json:"in_reply_to,omitempty"` + }{ + Body: body, + InReplyTo: commentID, + } + u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number) + req, err := s.client.NewRequest("POST", u, comment) + if err != nil { + return nil, nil, err + } + + c := new(PullRequestComment) + resp, err := s.client.Do(ctx, req, c) + if err != nil { + return nil, resp, err + } + + return c, resp, nil +} + // EditComment updates a pull request comment. +// A non-nil comment.Body must be provided. Other comment fields should be left nil. // // GitHub API docs: https://developer.github.com/v3/pulls/comments/#edit-a-comment -func (s *PullRequestsService) EditComment(ctx context.Context, owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) +func (s *PullRequestsService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *PullRequestComment) (*PullRequestComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("PATCH", u, comment) if err != nil { return nil, nil, err @@ -147,8 +178,8 @@ func (s *PullRequestsService) EditComment(ctx context.Context, owner string, rep // DeleteComment deletes a pull request comment. // // GitHub API docs: https://developer.github.com/v3/pulls/comments/#delete-a-comment -func (s *PullRequestsService) DeleteComment(ctx context.Context, owner string, repo string, number int) (*Response, error) { - u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) +func (s *PullRequestsService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/vendor/github.com/google/go-github/github/pulls_comments_test.go b/vendor/github.com/google/go-github/github/pulls_comments_test.go index e35b04f7b..76b78cf71 100644 --- a/vendor/github.com/google/go-github/github/pulls_comments_test.go +++ b/vendor/github.com/google/go-github/github/pulls_comments_test.go @@ -16,7 +16,7 @@ import ( ) func TestPullRequestsService_ListComments_allPulls(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments", func(w http.ResponseWriter, r *http.Request) { @@ -42,20 +42,20 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) { t.Errorf("PullRequests.ListComments returned error: %v", err) } - want := []*PullRequestComment{{ID: Int(1)}} + want := []*PullRequestComment{{ID: Int64(1)}} if !reflect.DeepEqual(pulls, want) { t.Errorf("PullRequests.ListComments returned %+v, want %+v", pulls, want) } } func TestPullRequestsService_ListComments_specificPull(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", mediaTypeReactionsPreview) - fmt.Fprint(w, `[{"id":1}]`) + fmt.Fprint(w, `[{"id":1, "pull_request_review_id":42}]`) }) pulls, _, err := client.PullRequests.ListComments(context.Background(), "o", "r", 1, nil) @@ -63,19 +63,22 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) { t.Errorf("PullRequests.ListComments returned error: %v", err) } - want := []*PullRequestComment{{ID: Int(1)}} + want := []*PullRequestComment{{ID: Int64(1), PullRequestReviewID: Int64(42)}} if !reflect.DeepEqual(pulls, want) { t.Errorf("PullRequests.ListComments returned %+v, want %+v", pulls, want) } } func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListComments(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -89,19 +92,22 @@ func TestPullRequestsService_GetComment(t *testing.T) { t.Errorf("PullRequests.GetComment returned error: %v", err) } - want := &PullRequestComment{ID: Int(1)} + want := &PullRequestComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("PullRequests.GetComment returned %+v, want %+v", comment, want) } } func TestPullRequestsService_GetComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.GetComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestPullRequestsService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestComment{Body: String("b")} @@ -123,19 +129,22 @@ func TestPullRequestsService_CreateComment(t *testing.T) { t.Errorf("PullRequests.CreateComment returned error: %v", err) } - want := &PullRequestComment{ID: Int(1)} + want := &PullRequestComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("PullRequests.CreateComment returned %+v, want %+v", comment, want) } } func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.CreateComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestComment{Body: String("b")} @@ -157,19 +166,22 @@ func TestPullRequestsService_EditComment(t *testing.T) { t.Errorf("PullRequests.EditComment returned error: %v", err) } - want := &PullRequestComment{ID: Int(1)} + want := &PullRequestComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("PullRequests.EditComment returned %+v, want %+v", comment, want) } } func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.EditComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +195,9 @@ func TestPullRequestsService_DeleteComment(t *testing.T) { } func TestPullRequestsService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.PullRequests.DeleteComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/pulls_reviewers.go b/vendor/github.com/google/go-github/github/pulls_reviewers.go index 15b0d8464..a1d785315 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviewers.go +++ b/vendor/github.com/google/go-github/github/pulls_reviewers.go @@ -32,9 +32,6 @@ func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeTeamReviewPreview) - r := new(PullRequest) resp, err := s.client.Do(ctx, req, r) if err != nil { @@ -59,9 +56,6 @@ func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo str return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeTeamReviewPreview) - reviewers := new(Reviewers) resp, err := s.client.Do(ctx, req, reviewers) if err != nil { @@ -81,8 +75,5 @@ func (s *PullRequestsService) RemoveReviewers(ctx context.Context, owner, repo s return nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeTeamReviewPreview) - - return s.client.Do(ctx, req, reviewers) + return s.client.Do(ctx, req, nil) } diff --git a/vendor/github.com/google/go-github/github/pulls_reviewers_test.go b/vendor/github.com/google/go-github/github/pulls_reviewers_test.go index fddea6d08..7c550e1bc 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviewers_test.go +++ b/vendor/github.com/google/go-github/github/pulls_reviewers_test.go @@ -14,13 +14,12 @@ import ( ) func TestRequestReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") testBody(t, r, `{"reviewers":["octocat","googlebot"],"team_reviewers":["justice-league","injustice-league"]}`+"\n") - testHeader(t, r, "Accept", mediaTypeTeamReviewPreview) fmt.Fprint(w, `{"number":1}`) }) @@ -36,12 +35,11 @@ func TestRequestReviewers(t *testing.T) { } func TestRemoveReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeTeamReviewPreview) testBody(t, r, `{"reviewers":["octocat","googlebot"],"team_reviewers":["justice-league"]}`+"\n") }) @@ -52,12 +50,11 @@ func TestRemoveReviewers(t *testing.T) { } func TestListReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeTeamReviewPreview) fmt.Fprint(w, `{"users":[{"login":"octocat","id":1}],"teams":[{"id":1,"name":"Justice League"}]}`) }) @@ -70,12 +67,12 @@ func TestListReviewers(t *testing.T) { Users: []*User{ { Login: String("octocat"), - ID: Int(1), + ID: Int64(1), }, }, Teams: []*Team{ { - ID: Int(1), + ID: Int64(1), Name: String("Justice League"), }, }, @@ -86,7 +83,7 @@ func TestListReviewers(t *testing.T) { } func TestListReviewers_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/pulls_reviews.go b/vendor/github.com/google/go-github/github/pulls_reviews.go index 7d2acc414..57d3c635e 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviews.go +++ b/vendor/github.com/google/go-github/github/pulls_reviews.go @@ -13,7 +13,7 @@ import ( // PullRequestReview represents a review of a pull request. type PullRequestReview struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` User *User `json:"user,omitempty"` Body *string `json:"body,omitempty"` SubmittedAt *time.Time `json:"submitted_at,omitempty"` @@ -94,7 +94,7 @@ func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo strin // Read more about it here - https://github.com/google/go-github/issues/540 // // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-review -func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) { +func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, number int, reviewID int64) (*PullRequestReview, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID) req, err := s.client.NewRequest("GET", u, nil) @@ -118,7 +118,7 @@ func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, // Read more about it here - https://github.com/google/go-github/issues/540 // // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review -func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) { +func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, repo string, number int, reviewID int64) (*PullRequestReview, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID) req, err := s.client.NewRequest("DELETE", u, nil) @@ -142,7 +142,7 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re // Read more about it here - https://github.com/google/go-github/issues/540 // // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review -func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int, opt *ListOptions) ([]*PullRequestComment, *Response, error) { +func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number int, reviewID int64, opt *ListOptions) ([]*PullRequestComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID) u, err := addOptions(u, opt) if err != nil { @@ -194,7 +194,7 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri // Read more about it here - https://github.com/google/go-github/issues/540 // // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review -func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo string, number, reviewID int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) { +func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo string, number int, reviewID int64, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/events", owner, repo, number, reviewID) req, err := s.client.NewRequest("POST", u, review) @@ -218,7 +218,7 @@ func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo stri // Read more about it here - https://github.com/google/go-github/issues/540 // // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review -func (s *PullRequestsService) DismissReview(ctx context.Context, owner, repo string, number, reviewID int, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) { +func (s *PullRequestsService) DismissReview(ctx context.Context, owner, repo string, number int, reviewID int64, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/dismissals", owner, repo, number, reviewID) req, err := s.client.NewRequest("PUT", u, review) diff --git a/vendor/github.com/google/go-github/github/pulls_reviews_test.go b/vendor/github.com/google/go-github/github/pulls_reviews_test.go index b69d76adc..58e301bd5 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviews_test.go +++ b/vendor/github.com/google/go-github/github/pulls_reviews_test.go @@ -15,7 +15,7 @@ import ( ) func TestPullRequestsService_ListReviews(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) { @@ -33,8 +33,8 @@ func TestPullRequestsService_ListReviews(t *testing.T) { } want := []*PullRequestReview{ - {ID: Int(1)}, - {ID: Int(2)}, + {ID: Int64(1)}, + {ID: Int64(2)}, } if !reflect.DeepEqual(reviews, want) { t.Errorf("PullRequests.ListReviews returned %+v, want %+v", reviews, want) @@ -42,12 +42,15 @@ func TestPullRequestsService_ListReviews(t *testing.T) { } func TestPullRequestsService_ListReviews_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListReviews(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_GetReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) { @@ -60,19 +63,22 @@ func TestPullRequestsService_GetReview(t *testing.T) { t.Errorf("PullRequests.GetReview returned error: %v", err) } - want := &PullRequestReview{ID: Int(1)} + want := &PullRequestReview{ID: Int64(1)} if !reflect.DeepEqual(review, want) { t.Errorf("PullRequests.GetReview returned %+v, want %+v", review, want) } } func TestPullRequestsService_GetReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.GetReview(context.Background(), "%", "r", 1, 1) testURLParseError(t, err) } func TestPullRequestsService_DeletePendingReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) { @@ -85,19 +91,22 @@ func TestPullRequestsService_DeletePendingReview(t *testing.T) { t.Errorf("PullRequests.DeletePendingReview returned error: %v", err) } - want := &PullRequestReview{ID: Int(1)} + want := &PullRequestReview{ID: Int64(1)} if !reflect.DeepEqual(review, want) { t.Errorf("PullRequests.DeletePendingReview returned %+v, want %+v", review, want) } } func TestPullRequestsService_DeletePendingReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.DeletePendingReview(context.Background(), "%", "r", 1, 1) testURLParseError(t, err) } func TestPullRequestsService_ListReviewComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -111,8 +120,8 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) { } want := []*PullRequestComment{ - {ID: Int(1)}, - {ID: Int(2)}, + {ID: Int64(1)}, + {ID: Int64(2)}, } if !reflect.DeepEqual(comments, want) { t.Errorf("PullRequests.ListReviewComments returned %+v, want %+v", comments, want) @@ -120,7 +129,7 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) { } func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -138,12 +147,15 @@ func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) { } func TestPullRequestsService_ListReviewComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListReviewComments(context.Background(), "%", "r", 1, 1, nil) testURLParseError(t, err) } func TestPullRequestsService_CreateReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewRequest{ @@ -169,19 +181,22 @@ func TestPullRequestsService_CreateReview(t *testing.T) { t.Errorf("PullRequests.CreateReview returned error: %v", err) } - want := &PullRequestReview{ID: Int(1)} + want := &PullRequestReview{ID: Int64(1)} if !reflect.DeepEqual(review, want) { t.Errorf("PullRequests.CreateReview returned %+v, want %+v", review, want) } } func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.CreateReview(context.Background(), "%", "r", 1, &PullRequestReviewRequest{}) testURLParseError(t, err) } func TestPullRequestsService_SubmitReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewRequest{ @@ -206,19 +221,22 @@ func TestPullRequestsService_SubmitReview(t *testing.T) { t.Errorf("PullRequests.SubmitReview returned error: %v", err) } - want := &PullRequestReview{ID: Int(1)} + want := &PullRequestReview{ID: Int64(1)} if !reflect.DeepEqual(review, want) { t.Errorf("PullRequests.SubmitReview returned %+v, want %+v", review, want) } } func TestPullRequestsService_SubmitReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.SubmitReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewRequest{}) testURLParseError(t, err) } func TestPullRequestsService_DismissReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewDismissalRequest{Message: String("m")} @@ -240,13 +258,16 @@ func TestPullRequestsService_DismissReview(t *testing.T) { t.Errorf("PullRequests.DismissReview returned error: %v", err) } - want := &PullRequestReview{ID: Int(1)} + want := &PullRequestReview{ID: Int64(1)} if !reflect.DeepEqual(review, want) { t.Errorf("PullRequests.DismissReview returned %+v, want %+v", review, want) } } func TestPullRequestsService_DismissReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.DismissReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewDismissalRequest{}) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/pulls_test.go b/vendor/github.com/google/go-github/github/pulls_test.go index ea31e5216..696a1c7fa 100644 --- a/vendor/github.com/google/go-github/github/pulls_test.go +++ b/vendor/github.com/google/go-github/github/pulls_test.go @@ -17,11 +17,13 @@ import ( ) func TestPullRequestsService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) testFormValues(t, r, values{ "state": "closed", "head": "h", @@ -46,16 +48,21 @@ func TestPullRequestsService_List(t *testing.T) { } func TestPullRequestsService_List_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.List(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestPullRequestsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) fmt.Fprint(w, `{"number":1}`) }) @@ -70,9 +77,10 @@ func TestPullRequestsService_Get(t *testing.T) { } } -func TestPullRequestsService_GetRawDiff(t *testing.T) { - setup() +func TestPullRequestsService_GetRaw_diff(t *testing.T) { + client, mux, _, teardown := setup() defer teardown() + const rawStr = "@@diff content" mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -81,19 +89,20 @@ func TestPullRequestsService_GetRawDiff(t *testing.T) { fmt.Fprint(w, rawStr) }) - ret, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Diff}) + got, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Diff}) if err != nil { t.Fatalf("PullRequests.GetRaw returned error: %v", err) } - - if ret != rawStr { - t.Errorf("PullRequests.GetRaw returned %s want %s", ret, rawStr) + want := rawStr + if got != want { + t.Errorf("PullRequests.GetRaw returned %s want %s", got, want) } } -func TestPullRequestsService_GetRawPatch(t *testing.T) { - setup() +func TestPullRequestsService_GetRaw_patch(t *testing.T) { + client, mux, _, teardown := setup() defer teardown() + const rawStr = "@@patch content" mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -102,18 +111,18 @@ func TestPullRequestsService_GetRawPatch(t *testing.T) { fmt.Fprint(w, rawStr) }) - ret, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Patch}) + got, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Patch}) if err != nil { t.Fatalf("PullRequests.GetRaw returned error: %v", err) } - - if ret != rawStr { - t.Errorf("PullRequests.GetRaw returned %s want %s", ret, rawStr) + want := rawStr + if got != want { + t.Errorf("PullRequests.GetRaw returned %s want %s", got, want) } } -func TestPullRequestsService_GetRawInvalid(t *testing.T) { - setup() +func TestPullRequestsService_GetRaw_invalid(t *testing.T) { + client, _, _, teardown := setup() defer teardown() _, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{100}) @@ -125,8 +134,61 @@ func TestPullRequestsService_GetRawInvalid(t *testing.T) { } } +func TestPullRequestsService_Get_links(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "number":1, + "_links":{ + "self":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347"}, + "html":{"href":"https://github.com/octocat/Hello-World/pull/1347"}, + "issue":{"href":"https://api.github.com/repos/octocat/Hello-World/issues/1347"}, + "comments":{"href":"https://api.github.com/repos/octocat/Hello-World/issues/1347/comments"}, + "review_comments":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments"}, + "review_comment":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"}, + "commits":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347/commits"}, + "statuses":{"href":"https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e"} + } + }`) + }) + + pull, _, err := client.PullRequests.Get(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("PullRequests.Get returned error: %v", err) + } + + want := &PullRequest{ + Number: Int(1), + Links: &PRLinks{ + Self: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347"), + }, HTML: &PRLink{ + HRef: String("https://github.com/octocat/Hello-World/pull/1347"), + }, Issue: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/issues/1347"), + }, Comments: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/issues/1347/comments"), + }, ReviewComments: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments"), + }, ReviewComment: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"), + }, Commits: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347/commits"), + }, Statuses: &PRLink{ + HRef: String("https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e"), + }, + }, + } + if !reflect.DeepEqual(pull, want) { + t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want) + } +} + func TestPullRequestsService_Get_headAndBase(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -143,11 +205,11 @@ func TestPullRequestsService_Get_headAndBase(t *testing.T) { Number: Int(1), Head: &PullRequestBranch{ Ref: String("r2"), - Repo: &Repository{ID: Int(2)}, + Repo: &Repository{ID: Int64(2)}, }, Base: &PullRequestBranch{ Ref: String("r1"), - Repo: &Repository{ID: Int(1)}, + Repo: &Repository{ID: Int64(1)}, }, } if !reflect.DeepEqual(pull, want) { @@ -156,7 +218,7 @@ func TestPullRequestsService_Get_headAndBase(t *testing.T) { } func TestPullRequestsService_Get_urlFields(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -195,12 +257,15 @@ func TestPullRequestsService_Get_urlFields(t *testing.T) { } func TestPullRequestsService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Get(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestPullRequestsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &NewPullRequest{Title: String("t")} @@ -210,6 +275,7 @@ func TestPullRequestsService_Create(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeLabelDescriptionSearchPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -229,12 +295,15 @@ func TestPullRequestsService_Create(t *testing.T) { } func TestPullRequestsService_Create_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Create(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestPullRequestsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() tests := []struct { @@ -264,8 +333,10 @@ func TestPullRequestsService_Edit(t *testing.T) { for i, tt := range tests { madeRequest := false + acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview} mux.HandleFunc(fmt.Sprintf("/repos/o/r/pulls/%v", i), func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) testBody(t, r, tt.wantUpdate+"\n") io.WriteString(w, tt.sendResponse) madeRequest = true @@ -287,12 +358,15 @@ func TestPullRequestsService_Edit(t *testing.T) { } func TestPullRequestsService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Edit(context.Background(), "%", "r", 1, &PullRequest{}) testURLParseError(t, err) } func TestPullRequestsService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -350,7 +424,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) { } func TestPullRequestsService_ListFiles(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/files", func(w http.ResponseWriter, r *http.Request) { @@ -412,7 +486,7 @@ func TestPullRequestsService_ListFiles(t *testing.T) { } func TestPullRequestsService_IsMerged(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) { @@ -432,7 +506,7 @@ func TestPullRequestsService_IsMerged(t *testing.T) { } func TestPullRequestsService_Merge(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) { @@ -463,7 +537,7 @@ func TestPullRequestsService_Merge(t *testing.T) { // Test that different merge options produce expected PUT requests. See issue https://github.com/google/go-github/issues/500. func TestPullRequestsService_Merge_options(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() tests := []struct { diff --git a/vendor/github.com/google/go-github/github/reactions.go b/vendor/github.com/google/go-github/github/reactions.go index 739413d71..ddc055cb1 100644 --- a/vendor/github.com/google/go-github/github/reactions.go +++ b/vendor/github.com/google/go-github/github/reactions.go @@ -19,8 +19,9 @@ type ReactionsService service // Reaction represents a GitHub reaction. type Reaction struct { // ID is the Reaction ID. - ID *int `json:"id,omitempty"` - User *User `json:"user,omitempty"` + ID *int64 `json:"id,omitempty"` + User *User `json:"user,omitempty"` + NodeID *string `json:"node_id,omitempty"` // Content is the type of reaction. // Possible values are: // "+1", "-1", "laugh", "confused", "heart", "hooray". @@ -46,7 +47,7 @@ func (r Reaction) String() string { // ListCommentReactions lists the reactions for a commit comment. // // GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment -func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) { +func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opt *ListOptions) ([]*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) u, err := addOptions(u, opt) if err != nil { @@ -58,7 +59,7 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -73,9 +74,10 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo // CreateCommentReaction creates a reaction for a commit comment. // Note that if you have already created a reaction of type content, the // previously created reaction will be returned with Status: 200 OK. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // // GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment -func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) { +func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) body := &Reaction{Content: String(content)} @@ -84,7 +86,7 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -111,7 +113,7 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -126,6 +128,7 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s // CreateIssueReaction creates a reaction for an issue. // Note that if you have already created a reaction of type content, the // previously created reaction will be returned with Status: 200 OK. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // // GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) { @@ -137,7 +140,7 @@ func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo s return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -152,7 +155,7 @@ func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo s // ListIssueCommentReactions lists the reactions for an issue comment. // // GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment -func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) { +func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opt *ListOptions) ([]*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) u, err := addOptions(u, opt) if err != nil { @@ -164,7 +167,7 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -179,9 +182,10 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, // CreateIssueCommentReaction creates a reaction for an issue comment. // Note that if you have already created a reaction of type content, the // previously created reaction will be returned with Status: 200 OK. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // // GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment -func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) { +func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) body := &Reaction{Content: String(content)} @@ -190,7 +194,7 @@ func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -205,7 +209,7 @@ func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, // ListPullRequestCommentReactions lists the reactions for a pull request review comment. // // GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment -func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) { +func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opt *ListOptions) ([]*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) u, err := addOptions(u, opt) if err != nil { @@ -217,7 +221,7 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -232,9 +236,10 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, // CreatePullRequestCommentReaction creates a reaction for a pull request review comment. // Note that if you have already created a reaction of type content, the // previously created reaction will be returned with Status: 200 OK. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // // GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment -func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) { +func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) body := &Reaction{Content: String(content)} @@ -243,7 +248,104 @@ func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. + req.Header.Set("Accept", mediaTypeReactionsPreview) + + m := &Reaction{} + resp, err := s.client.Do(ctx, req, m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// ListTeamDiscussionReactions lists the reactions for a team discussion. +// +// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion +func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opt *ListOptions) ([]*Reaction, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeReactionsPreview) + + var m []*Reaction + resp, err := s.client.Do(ctx, req, &m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// CreateTeamDiscussionReaction creates a reaction for a team discussion. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". +// +// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion +func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) + + body := &Reaction{Content: String(content)} + req, err := s.client.NewRequest("POST", u, body) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeReactionsPreview) + + m := &Reaction{} + resp, err := s.client.Do(ctx, req, m) + if err != nil { + return nil, resp, err + } + + return m, resp, nil +} + +// ListTeamDiscussionCommentReactions lists the reactions for a team discussion comment. +// +// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion-comment +func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opt *ListOptions) ([]*Reaction, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeReactionsPreview) + + var m []*Reaction + resp, err := s.client.Do(ctx, req, &m) + + return m, resp, nil +} + +// CreateTeamDiscussionCommentReaction creates a reaction for a team discussion comment. +// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". +// +// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion-comment +func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) + + body := &Reaction{Content: String(content)} + req, err := s.client.NewRequest("POST", u, body) + if err != nil { + return nil, nil, err + } + req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -258,7 +360,7 @@ func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, // DeleteReaction deletes a reaction. // // GitHub API docs: https://developer.github.com/v3/reaction/reactions/#delete-a-reaction-archive -func (s *ReactionsService) DeleteReaction(ctx context.Context, id int) (*Response, error) { +func (s *ReactionsService) DeleteReaction(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("reactions/%v", id) req, err := s.client.NewRequest("DELETE", u, nil) diff --git a/vendor/github.com/google/go-github/github/reactions_test.go b/vendor/github.com/google/go-github/github/reactions_test.go index 272529827..e1baec3f9 100644 --- a/vendor/github.com/google/go-github/github/reactions_test.go +++ b/vendor/github.com/google/go-github/github/reactions_test.go @@ -13,7 +13,7 @@ import ( ) func TestReactionsService_ListCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -28,13 +28,14 @@ func TestReactionsService_ListCommentReactions(t *testing.T) { if err != nil { t.Errorf("ListCommentReactions returned error: %v", err) } - if want := []*Reaction{{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")}}; !reflect.DeepEqual(got, want) { + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { t.Errorf("ListCommentReactions = %+v, want %+v", got, want) } } func TestReactionsService_CreateCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -49,14 +50,14 @@ func TestReactionsService_CreateCommentReaction(t *testing.T) { if err != nil { t.Errorf("CreateCommentReaction returned error: %v", err) } - want := &Reaction{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")} + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} if !reflect.DeepEqual(got, want) { t.Errorf("CreateCommentReaction = %+v, want %+v", got, want) } } func TestReactionsService_ListIssueReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -71,13 +72,14 @@ func TestReactionsService_ListIssueReactions(t *testing.T) { if err != nil { t.Errorf("ListIssueReactions returned error: %v", err) } - if want := []*Reaction{{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")}}; !reflect.DeepEqual(got, want) { + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { t.Errorf("ListIssueReactions = %+v, want %+v", got, want) } } func TestReactionsService_CreateIssueReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -92,14 +94,14 @@ func TestReactionsService_CreateIssueReaction(t *testing.T) { if err != nil { t.Errorf("CreateIssueReaction returned error: %v", err) } - want := &Reaction{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")} + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} if !reflect.DeepEqual(got, want) { t.Errorf("CreateIssueReaction = %+v, want %+v", got, want) } } func TestReactionsService_ListIssueCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -114,13 +116,14 @@ func TestReactionsService_ListIssueCommentReactions(t *testing.T) { if err != nil { t.Errorf("ListIssueCommentReactions returned error: %v", err) } - if want := []*Reaction{{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")}}; !reflect.DeepEqual(got, want) { + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { t.Errorf("ListIssueCommentReactions = %+v, want %+v", got, want) } } func TestReactionsService_CreateIssueCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -135,14 +138,14 @@ func TestReactionsService_CreateIssueCommentReaction(t *testing.T) { if err != nil { t.Errorf("CreateIssueCommentReaction returned error: %v", err) } - want := &Reaction{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")} + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} if !reflect.DeepEqual(got, want) { t.Errorf("CreateIssueCommentReaction = %+v, want %+v", got, want) } } func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -157,13 +160,14 @@ func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) { if err != nil { t.Errorf("ListPullRequestCommentReactions returned error: %v", err) } - if want := []*Reaction{{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")}}; !reflect.DeepEqual(got, want) { + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { t.Errorf("ListPullRequestCommentReactions = %+v, want %+v", got, want) } } func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -178,14 +182,102 @@ func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) { if err != nil { t.Errorf("CreatePullRequestCommentReaction returned error: %v", err) } - want := &Reaction{ID: Int(1), User: &User{Login: String("l"), ID: Int(2)}, Content: String("+1")} + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} if !reflect.DeepEqual(got, want) { t.Errorf("CreatePullRequestCommentReaction = %+v, want %+v", got, want) } } +func TestReactionsService_ListTeamDiscussionReactions(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusOK) + w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) + }) + + got, _, err := client.Reactions.ListTeamDiscussionReactions(context.Background(), 1, 2, nil) + if err != nil { + t.Errorf("ListTeamDiscussionReactions returned error: %v", err) + } + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { + t.Errorf("ListTeamDiscussionReactions = %+v, want %+v", got, want) + } +} + +func TestReactionsService_CreateTeamDiscussionReaction(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusCreated) + w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) + }) + + got, _, err := client.Reactions.CreateTeamDiscussionReaction(context.Background(), 1, 2, "+1") + if err != nil { + t.Errorf("CreateTeamDiscussionReaction returned error: %v", err) + } + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} + if !reflect.DeepEqual(got, want) { + t.Errorf("CreateTeamDiscussionReaction = %+v, want %+v", got, want) + } +} + +func TestReactionService_ListTeamDiscussionCommentReactions(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusOK) + w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) + }) + + got, _, err := client.Reactions.ListTeamDiscussionCommentReactions(context.Background(), 1, 2, 3, nil) + if err != nil { + t.Errorf("ListTeamDiscussionCommentReactions returned error: %v", err) + } + want := []*Reaction{{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")}} + if !reflect.DeepEqual(got, want) { + t.Errorf("ListTeamDiscussionCommentReactions = %+v, want %+v", got, want) + } +} + +func TestReactionService_CreateTeamDiscussionCommentReaction(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusCreated) + w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) + }) + + got, _, err := client.Reactions.CreateTeamDiscussionCommentReaction(context.Background(), 1, 2, 3, "+1") + if err != nil { + t.Errorf("CreateTeamDiscussionCommentReaction returned error: %v", err) + } + want := &Reaction{ID: Int64(1), User: &User{Login: String("l"), ID: Int64(2)}, Content: String("+1")} + if !reflect.DeepEqual(got, want) { + t.Errorf("CreateTeamDiscussionCommentReaction = %+v, want %+v", got, want) + } +} + func TestReactionsService_DeleteReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/reactions/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/repos.go b/vendor/github.com/google/go-github/github/repos.go index b6d98cc16..d09b5cc87 100644 --- a/vendor/github.com/google/go-github/github/repos.go +++ b/vendor/github.com/google/go-github/github/repos.go @@ -7,7 +7,6 @@ package github import ( "context" - "encoding/json" "fmt" "strings" ) @@ -20,7 +19,8 @@ type RepositoriesService service // Repository represents a GitHub repository. type Repository struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` Owner *User `json:"owner,omitempty"` Name *string `json:"name,omitempty"` FullName *string `json:"full_name,omitempty"` @@ -39,7 +39,7 @@ type Repository struct { SSHURL *string `json:"ssh_url,omitempty"` SVNURL *string `json:"svn_url,omitempty"` Language *string `json:"language,omitempty"` - Fork *bool `json:"fork"` + Fork *bool `json:"fork,omitempty"` ForksCount *int `json:"forks_count,omitempty"` NetworkCount *int `json:"network_count,omitempty"` OpenIssuesCount *int `json:"open_issues_count,omitempty"` @@ -56,21 +56,23 @@ type Repository struct { AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"` AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"` Topics []string `json:"topics,omitempty"` + Archived *bool `json:"archived,omitempty"` // Only provided when using RepositoriesService.Get while in preview License *License `json:"license,omitempty"` // Additional mutable fields when creating and editing a repository - Private *bool `json:"private"` - HasIssues *bool `json:"has_issues"` - HasWiki *bool `json:"has_wiki"` - HasPages *bool `json:"has_pages"` - HasDownloads *bool `json:"has_downloads"` + Private *bool `json:"private,omitempty"` + HasIssues *bool `json:"has_issues,omitempty"` + HasWiki *bool `json:"has_wiki,omitempty"` + HasPages *bool `json:"has_pages,omitempty"` + HasProjects *bool `json:"has_projects,omitempty"` + HasDownloads *bool `json:"has_downloads,omitempty"` LicenseTemplate *string `json:"license_template,omitempty"` GitignoreTemplate *string `json:"gitignore_template,omitempty"` // Creating an organization repository. Required for non-owners. - TeamID *int `json:"team_id"` + TeamID *int64 `json:"team_id,omitempty"` // API URLs URL *string `json:"url,omitempty"` @@ -177,7 +179,7 @@ func (s *RepositoriesService) List(ctx context.Context, user string, opt *Reposi } // TODO: remove custom Accept headers when APIs fully launch. - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) var repos []*Repository @@ -215,7 +217,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opt *Re } // TODO: remove custom Accept headers when APIs fully launch. - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) var repos []*Repository @@ -231,9 +233,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opt *Re // RepositoriesService.ListAll method. type RepositoryListAllOptions struct { // ID of the last repository seen - Since int `url:"since,omitempty"` - - ListOptions + Since int64 `url:"since,omitempty"` } // ListAll lists all GitHub repositories in the order that they were created. @@ -259,10 +259,40 @@ func (s *RepositoriesService) ListAll(ctx context.Context, opt *RepositoryListAl return repos, resp, nil } +// createRepoRequest is a subset of Repository and is used internally +// by Create to pass only the known fields for the endpoint. +// +// See https://github.com/google/go-github/issues/1014 for more +// information. +type createRepoRequest struct { + // Name is required when creating a repo. + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + Homepage *string `json:"homepage,omitempty"` + + Private *bool `json:"private,omitempty"` + HasIssues *bool `json:"has_issues,omitempty"` + HasProjects *bool `json:"has_projects,omitempty"` + HasWiki *bool `json:"has_wiki,omitempty"` + + // Creating an organization repository. Required for non-owners. + TeamID *int64 `json:"team_id,omitempty"` + + AutoInit *bool `json:"auto_init,omitempty"` + GitignoreTemplate *string `json:"gitignore_template,omitempty"` + LicenseTemplate *string `json:"license_template,omitempty"` + AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"` + AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"` + AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"` +} + // Create a new repository. If an organization is specified, the new // repository will be created under that org. If the empty string is // specified, it will be created for the authenticated user. // +// Note that only a subset of the repo fields are used and repo must +// not be nil. +// // GitHub API docs: https://developer.github.com/v3/repos/#create func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) { var u string @@ -272,7 +302,24 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo u = "user/repos" } - req, err := s.client.NewRequest("POST", u, repo) + repoReq := &createRepoRequest{ + Name: repo.Name, + Description: repo.Description, + Homepage: repo.Homepage, + Private: repo.Private, + HasIssues: repo.HasIssues, + HasProjects: repo.HasProjects, + HasWiki: repo.HasWiki, + TeamID: repo.TeamID, + AutoInit: repo.AutoInit, + GitignoreTemplate: repo.GitignoreTemplate, + LicenseTemplate: repo.LicenseTemplate, + AllowSquashMerge: repo.AllowSquashMerge, + AllowMergeCommit: repo.AllowMergeCommit, + AllowRebaseMerge: repo.AllowRebaseMerge, + } + + req, err := s.client.NewRequest("POST", u, repoReq) if err != nil { return nil, nil, err } @@ -298,7 +345,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep // TODO: remove custom Accept header when the license support fully launches // https://developer.github.com/v3/licenses/#get-a-repositorys-license - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) repository := new(Repository) @@ -335,17 +382,13 @@ func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo // GetByID fetches a repository. // // Note: GetByID uses the undocumented GitHub API endpoint /repositories/:id. -func (s *RepositoriesService) GetByID(ctx context.Context, id int) (*Repository, *Response, error) { +func (s *RepositoriesService) GetByID(ctx context.Context, id int64) (*Repository, *Response, error) { u := fmt.Sprintf("repositories/%d", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when the license support fully launches - // https://developer.github.com/v3/licenses/#get-a-repositorys-license - req.Header.Set("Accept", mediaTypeLicensesPreview) - repository := new(Repository) resp, err := s.client.Do(ctx, req, repository) if err != nil { @@ -390,7 +433,7 @@ func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (* // Contributor represents a repository contributor type Contributor struct { Login *string `json:"login,omitempty"` - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` AvatarURL *string `json:"avatar_url,omitempty"` GravatarID *string `json:"gravatar_id,omitempty"` URL *string `json:"url,omitempty"` @@ -405,7 +448,7 @@ type Contributor struct { EventsURL *string `json:"events_url,omitempty"` ReceivedEventsURL *string `json:"received_events_url,omitempty"` Type *string `json:"type,omitempty"` - SiteAdmin *bool `json:"site_admin"` + SiteAdmin *bool `json:"site_admin,omitempty"` Contributions *int `json:"contributions,omitempty"` } @@ -483,6 +526,8 @@ func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo return nil, nil, err } + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + var teams []*Team resp, err := s.client.Do(ctx, req, &teams) if err != nil { @@ -556,45 +601,40 @@ type RequiredStatusChecks struct { Contexts []string `json:"contexts"` } +// RequiredStatusChecksRequest represents a request to edit a protected branch's status checks. +type RequiredStatusChecksRequest struct { + Strict *bool `json:"strict,omitempty"` + Contexts []string `json:"contexts,omitempty"` +} + // PullRequestReviewsEnforcement represents the pull request reviews enforcement of a protected branch. type PullRequestReviewsEnforcement struct { // Specifies which users and teams can dismiss pull request reviews. DismissalRestrictions DismissalRestrictions `json:"dismissal_restrictions"` // Specifies if approved reviews are dismissed automatically, when a new commit is pushed. DismissStaleReviews bool `json:"dismiss_stale_reviews"` + // RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner. + RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"` + // RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged. + // Valid values are 1-6. + RequiredApprovingReviewCount int `json:"required_approving_review_count"` } // PullRequestReviewsEnforcementRequest represents request to set the pull request review // enforcement of a protected branch. It is separate from PullRequestReviewsEnforcement above // because the request structure is different from the response structure. type PullRequestReviewsEnforcementRequest struct { - // Specifies which users and teams should be allowed to dismiss pull request reviews. Can be nil to disable the restrictions. - DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions"` + // Specifies which users and teams should be allowed to dismiss pull request reviews. + // User and team dismissal restrictions are only available for + // organization-owned repositories. Must be nil for personal repositories. + DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"` // Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required) DismissStaleReviews bool `json:"dismiss_stale_reviews"` -} - -// MarshalJSON implements the json.Marshaler interface. -// Converts nil value of PullRequestReviewsEnforcementRequest.DismissalRestrictionsRequest to empty array -func (req PullRequestReviewsEnforcementRequest) MarshalJSON() ([]byte, error) { - if req.DismissalRestrictionsRequest == nil { - newReq := struct { - R []interface{} `json:"dismissal_restrictions"` - D bool `json:"dismiss_stale_reviews"` - }{ - R: []interface{}{}, - D: req.DismissStaleReviews, - } - return json.Marshal(newReq) - } - newReq := struct { - R *DismissalRestrictionsRequest `json:"dismissal_restrictions"` - D bool `json:"dismiss_stale_reviews"` - }{ - R: req.DismissalRestrictionsRequest, - D: req.DismissStaleReviews, - } - return json.Marshal(newReq) + // RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner. + RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"` + // RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged. + // Valid values are 1-6. + RequiredApprovingReviewCount int `json:"required_approving_review_count"` } // PullRequestReviewsEnforcementUpdate represents request to patch the pull request review @@ -605,6 +645,11 @@ type PullRequestReviewsEnforcementUpdate struct { DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"` // Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. Can be omitted. DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"` + // RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner. + RequireCodeOwnerReviews bool `json:"require_code_owner_reviews,omitempty"` + // RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged. + // Valid values are 1 - 6. + RequiredApprovingReviewCount int `json:"required_approving_review_count"` } // AdminEnforcement represents the configuration to enforce required status checks for repository administrators. @@ -645,11 +690,19 @@ type DismissalRestrictions struct { // restriction to allows only specific users or teams to dimiss pull request reviews. It is // separate from DismissalRestrictions above because the request structure is // different from the response structure. +// Note: Both Users and Teams must be nil, or both must be non-nil. type DismissalRestrictionsRequest struct { - // The list of user logins who can dismiss pull request reviews. (Required; use []string{} instead of nil for empty list.) - Users []string `json:"users"` - // The list of team slugs which can dismiss pull request reviews. (Required; use []string{} instead of nil for empty list.) - Teams []string `json:"teams"` + // The list of user logins who can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.) + Users *[]string `json:"users,omitempty"` + // The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.) + Teams *[]string `json:"teams,omitempty"` +} + +// SignaturesProtectedBranch represents the protection status of an individual branch. +type SignaturesProtectedBranch struct { + URL *string `json:"url,omitempty"` + // Commits pushed to matching branches must have verified signatures. + Enabled *bool `json:"enabled,omitempty"` } // ListBranches lists branches for the specified repository. @@ -668,7 +721,7 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) var branches []*Branch resp, err := s.client.Do(ctx, req, &branches) @@ -690,7 +743,7 @@ func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) b := new(Branch) resp, err := s.client.Do(ctx, req, b) @@ -712,7 +765,7 @@ func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, re } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) p := new(Protection) resp, err := s.client.Do(ctx, req, p) @@ -734,7 +787,7 @@ func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) p := new(RequiredStatusChecks) resp, err := s.client.Do(ctx, req, p) @@ -756,7 +809,7 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) resp, err = s.client.Do(ctx, req, &contexts) if err != nil { @@ -777,7 +830,7 @@ func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) p := new(Protection) resp, err := s.client.Do(ctx, req, p) @@ -799,11 +852,91 @@ func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) return s.client.Do(ctx, req, nil) } +// GetSignaturesProtectedBranch gets required signatures of protected branch. +// +// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-required-signatures-of-protected-branch +func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeSignaturePreview) + + p := new(SignaturesProtectedBranch) + resp, err := s.client.Do(ctx, req, p) + if err != nil { + return nil, resp, err + } + + return p, resp, nil +} + +// RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch. +// It requires admin access and branch protection to be enabled. +// +// GitHub API docs: https://developer.github.com/v3/repos/branches/#add-required-signatures-of-protected-branch +func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeSignaturePreview) + + r := new(SignaturesProtectedBranch) + resp, err := s.client.Do(ctx, req, r) + if err != nil { + return nil, resp, err + } + + return r, resp, err +} + +// OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch. +// +// GitHub API docs: https://developer.github.com/v3/repos/branches/#remove-required-signatures-of-protected-branch +func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeSignaturePreview) + + return s.client.Do(ctx, req, nil) +} + +// UpdateRequiredStatusChecks updates the required status checks for a given protected branch. +// +// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch +func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, owner, repo, branch string, sreq *RequiredStatusChecksRequest) (*RequiredStatusChecks, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch) + req, err := s.client.NewRequest("PATCH", u, sreq) + if err != nil { + return nil, nil, err + } + + sc := new(RequiredStatusChecks) + resp, err := s.client.Do(ctx, req, sc) + if err != nil { + return nil, resp, err + } + + return sc, resp, nil +} + // License gets the contents of a repository's license if one is detected. // // GitHub API docs: https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license @@ -834,7 +967,7 @@ func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Contex } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) resp, err := s.client.Do(ctx, req, r) @@ -857,7 +990,7 @@ func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Con } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) resp, err := s.client.Do(ctx, req, r) @@ -885,7 +1018,7 @@ func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) resp, err := s.client.Do(ctx, req, r) @@ -907,7 +1040,7 @@ func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Con } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) return s.client.Do(ctx, req, nil) } @@ -923,7 +1056,7 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(AdminEnforcement) resp, err := s.client.Do(ctx, req, r) @@ -946,7 +1079,7 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(AdminEnforcement) resp, err := s.client.Do(ctx, req, r) @@ -968,20 +1101,20 @@ func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner, } // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) return s.client.Do(ctx, req, nil) } -// Topics represents a collection of repository topics. -type Topics struct { - Names []string `json:"names,omitempty"` +// repositoryTopics represents a collection of repository topics. +type repositoryTopics struct { + Names []string `json:"names"` } // ListAllTopics lists topics for a repository. // // GitHub API docs: https://developer.github.com/v3/repos/#list-all-topics-for-a-repository -func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) (*Topics, *Response, error) { +func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) { u := fmt.Sprintf("repos/%v/%v/topics", owner, repo) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -991,21 +1124,27 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) - topics := new(Topics) + topics := new(repositoryTopics) resp, err := s.client.Do(ctx, req, topics) if err != nil { return nil, resp, err } - return topics, resp, nil + return topics.Names, resp, nil } // ReplaceAllTopics replaces topics for a repository. // // GitHub API docs: https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository -func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics *Topics) (*Topics, *Response, error) { +func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) { u := fmt.Sprintf("repos/%v/%v/topics", owner, repo) - req, err := s.client.NewRequest("PUT", u, topics) + t := &repositoryTopics{ + Names: topics, + } + if t.Names == nil { + t.Names = []string{} + } + req, err := s.client.NewRequest("PUT", u, t) if err != nil { return nil, nil, err } @@ -1013,11 +1152,46 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) - t := new(Topics) + t = new(repositoryTopics) resp, err := s.client.Do(ctx, req, t) if err != nil { return nil, resp, err } - return t, resp, nil + return t.Names, resp, nil +} + +// TransferRequest represents a request to transfer a repository. +type TransferRequest struct { + NewOwner string `json:"new_owner"` + TeamID []int64 `json:"team_ids,omitempty"` +} + +// Transfer transfers a repository from one account or organization to another. +// +// This method might return an *AcceptedError and a status code of +// 202. This is because this is the status that GitHub returns to signify that +// it has now scheduled the transfer of the repository in a background task. +// A follow up request, after a delay of a second or so, should result +// in a successful request. +// +// GitHub API docs: https://developer.github.com/v3/repos/#transfer-a-repository +func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo) + + req, err := s.client.NewRequest("POST", u, &transfer) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeRepositoryTransferPreview) + + r := new(Repository) + resp, err := s.client.Do(ctx, req, r) + if err != nil { + return nil, resp, err + } + + return r, resp, nil } diff --git a/vendor/github.com/google/go-github/github/repos_collaborators.go b/vendor/github.com/google/go-github/github/repos_collaborators.go index 100a92572..61ee9d39c 100644 --- a/vendor/github.com/google/go-github/github/repos_collaborators.go +++ b/vendor/github.com/google/go-github/github/repos_collaborators.go @@ -41,6 +41,8 @@ func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo return nil, nil, err } + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + var users []*User resp, err := s.client.Do(ctx, req, &users) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_collaborators_test.go b/vendor/github.com/google/go-github/github/repos_collaborators_test.go index 4ac23934c..c814a5f99 100644 --- a/vendor/github.com/google/go-github/github/repos_collaborators_test.go +++ b/vendor/github.com/google/go-github/github/repos_collaborators_test.go @@ -15,11 +15,12 @@ import ( ) func TestRepositoriesService_ListCollaborators(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprintf(w, `[{"id":1}, {"id":2}]`) }) @@ -32,14 +33,14 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) { t.Errorf("Repositories.ListCollaborators returned error: %v", err) } - want := []*User{{ID: Int(1)}, {ID: Int(2)}} + want := []*User{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(users, want) { t.Errorf("Repositori es.ListCollaborators returned %+v, want %+v", users, want) } } func TestRepositoriesService_ListCollaborators_withAffiliation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { @@ -57,19 +58,22 @@ func TestRepositoriesService_ListCollaborators_withAffiliation(t *testing.T) { t.Errorf("Repositories.ListCollaborators returned error: %v", err) } - want := []*User{{ID: Int(1)}, {ID: Int(2)}} + want := []*User{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(users, want) { t.Errorf("Repositories.ListCollaborators returned %+v, want %+v", users, want) } } func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListCollaborators(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_IsCollaborator_True(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -88,7 +92,7 @@ func TestRepositoriesService_IsCollaborator_True(t *testing.T) { } func TestRepositoriesService_IsCollaborator_False(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -107,12 +111,15 @@ func TestRepositoriesService_IsCollaborator_False(t *testing.T) { } func TestRepositoriesService_IsCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.IsCollaborator(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestRepositoryService_GetPermissionLevel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u/permission", func(w http.ResponseWriter, r *http.Request) { @@ -138,7 +145,7 @@ func TestRepositoryService_GetPermissionLevel(t *testing.T) { } func TestRepositoriesService_AddCollaborator(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() opt := &RepositoryAddCollaboratorOptions{Permission: "admin"} @@ -163,12 +170,15 @@ func TestRepositoriesService_AddCollaborator(t *testing.T) { } func TestRepositoriesService_AddCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.AddCollaborator(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_RemoveCollaborator(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +193,9 @@ func TestRepositoriesService_RemoveCollaborator(t *testing.T) { } func TestRepositoriesService_RemoveCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.RemoveCollaborator(context.Background(), "%", "%", "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/repos_comments.go b/vendor/github.com/google/go-github/github/repos_comments.go index 4830ee220..fa2377d40 100644 --- a/vendor/github.com/google/go-github/github/repos_comments.go +++ b/vendor/github.com/google/go-github/github/repos_comments.go @@ -15,7 +15,7 @@ import ( type RepositoryComment struct { HTMLURL *string `json:"html_url,omitempty"` URL *string `json:"url,omitempty"` - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` CommitID *string `json:"commit_id,omitempty"` User *User `json:"user,omitempty"` Reactions *Reactions `json:"reactions,omitempty"` @@ -110,7 +110,7 @@ func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sh // GetComment gets a single comment from a repository. // // GitHub API docs: https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment -func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int) (*RepositoryComment, *Response, error) { +func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -132,7 +132,7 @@ func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string // UpdateComment updates the body of a single comment. // // GitHub API docs: https://developer.github.com/v3/repos/comments/#update-a-commit-comment -func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int, comment *RepositoryComment) (*RepositoryComment, *Response, error) { +func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, comment *RepositoryComment) (*RepositoryComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) req, err := s.client.NewRequest("PATCH", u, comment) if err != nil { @@ -151,7 +151,7 @@ func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo str // DeleteComment deletes a single comment from a repository. // // GitHub API docs: https://developer.github.com/v3/repos/comments/#delete-a-commit-comment -func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_comments_test.go b/vendor/github.com/google/go-github/github/repos_comments_test.go index 249a37a36..0eb54eba2 100644 --- a/vendor/github.com/google/go-github/github/repos_comments_test.go +++ b/vendor/github.com/google/go-github/github/repos_comments_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments", func(w http.ResponseWriter, r *http.Request) { @@ -31,19 +31,22 @@ func TestRepositoriesService_ListComments(t *testing.T) { t.Errorf("Repositories.ListComments returned error: %v", err) } - want := []*RepositoryComment{{ID: Int(1)}, {ID: Int(2)}} + want := []*RepositoryComment{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(comments, want) { t.Errorf("Repositories.ListComments returned %+v, want %+v", comments, want) } } func TestRepositoriesService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListComments(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListCommitComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) { @@ -59,19 +62,22 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) { t.Errorf("Repositories.ListCommitComments returned error: %v", err) } - want := []*RepositoryComment{{ID: Int(1)}, {ID: Int(2)}} + want := []*RepositoryComment{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(comments, want) { t.Errorf("Repositories.ListCommitComments returned %+v, want %+v", comments, want) } } func TestRepositoriesService_ListCommitComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListCommitComments(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryComment{Body: String("b")} @@ -93,19 +99,22 @@ func TestRepositoriesService_CreateComment(t *testing.T) { t.Errorf("Repositories.CreateComment returned error: %v", err) } - want := &RepositoryComment{ID: Int(1)} + want := &RepositoryComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Repositories.CreateComment returned %+v, want %+v", comment, want) } } func TestRepositoriesService_CreateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateComment(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -119,19 +128,22 @@ func TestRepositoriesService_GetComment(t *testing.T) { t.Errorf("Repositories.GetComment returned error: %v", err) } - want := &RepositoryComment{ID: Int(1)} + want := &RepositoryComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Repositories.GetComment returned %+v, want %+v", comment, want) } } func TestRepositoriesService_GetComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetComment(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_UpdateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryComment{Body: String("b")} @@ -153,19 +165,22 @@ func TestRepositoriesService_UpdateComment(t *testing.T) { t.Errorf("Repositories.UpdateComment returned error: %v", err) } - want := &RepositoryComment{ID: Int(1)} + want := &RepositoryComment{ID: Int64(1)} if !reflect.DeepEqual(comment, want) { t.Errorf("Repositories.UpdateComment returned %+v, want %+v", comment, want) } } func TestRepositoriesService_UpdateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.UpdateComment(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -179,6 +194,9 @@ func TestRepositoriesService_DeleteComment(t *testing.T) { } func TestRepositoriesService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteComment(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/repos_commits.go b/vendor/github.com/google/go-github/github/repos_commits.go index 4451b6bb4..1acfa5ad1 100644 --- a/vendor/github.com/google/go-github/github/repos_commits.go +++ b/vendor/github.com/google/go-github/github/repos_commits.go @@ -48,16 +48,17 @@ func (c CommitStats) String() string { // CommitFile represents a file modified in a commit. type CommitFile struct { - SHA *string `json:"sha,omitempty"` - Filename *string `json:"filename,omitempty"` - Additions *int `json:"additions,omitempty"` - Deletions *int `json:"deletions,omitempty"` - Changes *int `json:"changes,omitempty"` - Status *string `json:"status,omitempty"` - Patch *string `json:"patch,omitempty"` - BlobURL *string `json:"blob_url,omitempty"` - RawURL *string `json:"raw_url,omitempty"` - ContentsURL *string `json:"contents_url,omitempty"` + SHA *string `json:"sha,omitempty"` + Filename *string `json:"filename,omitempty"` + Additions *int `json:"additions,omitempty"` + Deletions *int `json:"deletions,omitempty"` + Changes *int `json:"changes,omitempty"` + Status *string `json:"status,omitempty"` + Patch *string `json:"patch,omitempty"` + BlobURL *string `json:"blob_url,omitempty"` + RawURL *string `json:"raw_url,omitempty"` + ContentsURL *string `json:"contents_url,omitempty"` + PreviousFilename *string `json:"previous_filename,omitempty"` } func (c CommitFile) String() string { @@ -140,10 +141,9 @@ func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo strin } // GetCommit fetches the specified commit, including all details about it. -// todo: support media formats - https://github.com/google/go-github/issues/6 // // GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-single-commit -// See also: https://developer.github.com//v3/git/commits/#get-a-single-commit provides the same functionality +// See also: https://developer.github.com/v3/git/commits/#get-a-single-commit provides the same functionality func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha string) (*RepositoryCommit, *Response, error) { u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha) @@ -164,6 +164,32 @@ func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha st return commit, resp, nil } +// GetCommitRaw fetches the specified commit in raw (diff or patch) format. +func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, repo string, sha string, opt RawOptions) (string, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return "", nil, err + } + + switch opt.Type { + case Diff: + req.Header.Set("Accept", mediaTypeV3Diff) + case Patch: + req.Header.Set("Accept", mediaTypeV3Patch) + default: + return "", nil, fmt.Errorf("unsupported raw type %d", opt.Type) + } + + var buf bytes.Buffer + resp, err := s.client.Do(ctx, req, &buf) + if err != nil { + return "", resp, err + } + + return buf.String(), resp, nil +} + // GetCommitSHA1 gets the SHA-1 of a commit reference. If a last-known SHA1 is // supplied and no new commits have occurred, a 304 Unmodified response is returned. // @@ -193,7 +219,7 @@ func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, re // CompareCommits compares a range of commits with each other. // todo: support media formats - https://github.com/google/go-github/issues/6 // -// GitHub API docs: https://developer.github.com/v3/repos/commits/index.html#compare-two-commits +// GitHub API docs: https://developer.github.com/v3/repos/commits/#compare-two-commits func (s *RepositoriesService) CompareCommits(ctx context.Context, owner, repo string, base, head string) (*CommitsComparison, *Response, error) { u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, base, head) diff --git a/vendor/github.com/google/go-github/github/repos_commits_test.go b/vendor/github.com/google/go-github/github/repos_commits_test.go index 98eadabb3..3f7039da2 100644 --- a/vendor/github.com/google/go-github/github/repos_commits_test.go +++ b/vendor/github.com/google/go-github/github/repos_commits_test.go @@ -10,12 +10,13 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" "time" ) func TestRepositoriesService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() // given @@ -52,7 +53,7 @@ func TestRepositoriesService_ListCommits(t *testing.T) { } func TestRepositoriesService_GetCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/s", func(w http.ResponseWriter, r *http.Request) { @@ -126,8 +127,65 @@ func TestRepositoriesService_GetCommit(t *testing.T) { } } +func TestRepositoriesService_GetCommitRaw_diff(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + const rawStr = "@@diff content" + + mux.HandleFunc("/repos/o/r/commits/s", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeV3Diff) + fmt.Fprint(w, rawStr) + }) + + got, _, err := client.Repositories.GetCommitRaw(context.Background(), "o", "r", "s", RawOptions{Type: Diff}) + if err != nil { + t.Fatalf("Repositories.GetCommitRaw returned error: %v", err) + } + want := rawStr + if got != want { + t.Errorf("Repositories.GetCommitRaw returned %s want %s", got, want) + } +} + +func TestRepositoriesService_GetCommitRaw_patch(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + const rawStr = "@@patch content" + + mux.HandleFunc("/repos/o/r/commits/s", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeV3Patch) + fmt.Fprint(w, rawStr) + }) + + got, _, err := client.Repositories.GetCommitRaw(context.Background(), "o", "r", "s", RawOptions{Type: Patch}) + if err != nil { + t.Fatalf("Repositories.GetCommitRaw returned error: %v", err) + } + want := rawStr + if got != want { + t.Errorf("Repositories.GetCommitRaw returned %s want %s", got, want) + } +} + +func TestRepositoriesService_GetCommitRaw_invalid(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Repositories.GetCommitRaw(context.Background(), "o", "r", "s", RawOptions{100}) + if err == nil { + t.Fatal("Repositories.GetCommitRaw should return error") + } + if !strings.Contains(err.Error(), "unsupported raw type") { + t.Error("Repositories.GetCommitRaw should return unsupported raw type error") + } +} + func TestRepositoriesService_GetCommitSHA1(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const sha1 = "01234abcde" @@ -168,7 +226,7 @@ func TestRepositoriesService_GetCommitSHA1(t *testing.T) { } func TestRepositoriesService_CompareCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/compare/b...h", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/repos_community_health.go b/vendor/github.com/google/go-github/github/repos_community_health.go index b5c75d6f5..73d1d573b 100644 --- a/vendor/github.com/google/go-github/github/repos_community_health.go +++ b/vendor/github.com/google/go-github/github/repos_community_health.go @@ -21,10 +21,12 @@ type Metric struct { // CommunityHealthFiles represents the different files in the community health metrics response. type CommunityHealthFiles struct { - CodeOfConduct *Metric `json:"code_of_conduct"` - Contributing *Metric `json:"contributing"` - License *Metric `json:"license"` - Readme *Metric `json:"readme"` + CodeOfConduct *Metric `json:"code_of_conduct"` + Contributing *Metric `json:"contributing"` + IssueTemplate *Metric `json:"issue_template"` + PullRequestTemplate *Metric `json:"pull_request_template"` + License *Metric `json:"license"` + Readme *Metric `json:"readme"` } // CommunityHealthMetrics represents a response containing the community metrics of a repository. diff --git a/vendor/github.com/google/go-github/github/repos_community_health_test.go b/vendor/github.com/google/go-github/github/repos_community_health_test.go index a90c8c038..6092af0b1 100644 --- a/vendor/github.com/google/go-github/github/repos_community_health_test.go +++ b/vendor/github.com/google/go-github/github/repos_community_health_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/community/profile", func(w http.ResponseWriter, r *http.Request) { @@ -54,7 +54,7 @@ func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { t.Errorf("Repositories.GetCommunityHealthMetrics returned error: %v", err) } - updatedAt := time.Date(2017, 02, 28, 0, 0, 0, 0, time.UTC) + updatedAt := time.Date(2017, time.February, 28, 0, 0, 0, 0, time.UTC) want := &CommunityHealthMetrics{ HealthPercentage: Int(100), UpdatedAt: &updatedAt, diff --git a/vendor/github.com/google/go-github/github/repos_contents_test.go b/vendor/github.com/google/go-github/github/repos_contents_test.go index 498dfc810..29bab8d27 100644 --- a/vendor/github.com/google/go-github/github/repos_contents_test.go +++ b/vendor/github.com/google/go-github/github/repos_contents_test.go @@ -56,10 +56,12 @@ func TestRepositoryContent_GetContent(t *testing.T) { r := RepositoryContent{Encoding: tt.encoding, Content: tt.content} got, err := r.GetContent() if err != nil && !tt.wantErr { - t.Errorf("RepositoryContent(%q, %q) returned unexpected error: %v", tt.encoding, tt.content, err) + t.Errorf("RepositoryContent(%s, %s) returned unexpected error: %v", + stringOrNil(tt.encoding), stringOrNil(tt.content), err) } if err == nil && tt.wantErr { - t.Errorf("RepositoryContent(%q, %q) did not return unexpected error", tt.encoding, tt.content) + t.Errorf("RepositoryContent(%s, %s) did not return unexpected error", + stringOrNil(tt.encoding), stringOrNil(tt.content)) } if want := tt.want; got != want { t.Errorf("RepositoryContent.GetContent returned %+v, want %+v", got, want) @@ -67,8 +69,17 @@ func TestRepositoryContent_GetContent(t *testing.T) { } } +// stringOrNil converts a potentially null string pointer to string. +// For non-nil input pointer, the returned string is enclosed in double-quotes. +func stringOrNil(s *string) string { + if s == nil { + return "" + } + return fmt.Sprintf("%q", *s) +} + func TestRepositoriesService_GetReadme(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/readme", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -91,14 +102,14 @@ func TestRepositoriesService_GetReadme(t *testing.T) { } func TestRepositoriesService_DownloadContents_Success(t *testing.T) { - setup() + client, mux, serverURL, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[{ "type": "file", "name": "f", - "download_url": "`+server.URL+`/download/f" + "download_url": "`+serverURL+baseURLPath+`/download/f" }]`) }) mux.HandleFunc("/download/f", func(w http.ResponseWriter, r *http.Request) { @@ -123,7 +134,7 @@ func TestRepositoriesService_DownloadContents_Success(t *testing.T) { } func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -140,7 +151,7 @@ func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) { } func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -154,7 +165,7 @@ func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) { } func TestRepositoriesService_GetContents_File(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -177,7 +188,7 @@ func TestRepositoriesService_GetContents_File(t *testing.T) { } func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p#?%/中.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -190,7 +201,7 @@ func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) { } func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/some directory/file.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -203,7 +214,7 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) { } func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/some directory+name/file.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -216,7 +227,7 @@ func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) { } func TestRepositoriesService_GetContents_Directory(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -244,7 +255,7 @@ func TestRepositoriesService_GetContents_Directory(t *testing.T) { } func TestRepositoriesService_CreateFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") @@ -282,7 +293,7 @@ func TestRepositoriesService_CreateFile(t *testing.T) { } func TestRepositoriesService_UpdateFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") @@ -322,7 +333,7 @@ func TestRepositoriesService_UpdateFile(t *testing.T) { } func TestRepositoriesService_DeleteFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") @@ -358,7 +369,7 @@ func TestRepositoriesService_DeleteFile(t *testing.T) { } func TestRepositoriesService_GetArchiveLink(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") diff --git a/vendor/github.com/google/go-github/github/repos_deployments.go b/vendor/github.com/google/go-github/github/repos_deployments.go index ec0e84215..604632e91 100644 --- a/vendor/github.com/google/go-github/github/repos_deployments.go +++ b/vendor/github.com/google/go-github/github/repos_deployments.go @@ -9,12 +9,13 @@ import ( "context" "encoding/json" "fmt" + "strings" ) // Deployment represents a deployment in a repo type Deployment struct { URL *string `json:"url,omitempty"` - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` SHA *string `json:"sha,omitempty"` Ref *string `json:"ref,omitempty"` Task *string `json:"task,omitempty"` @@ -26,6 +27,7 @@ type Deployment struct { UpdatedAt *Timestamp `json:"updated_at,omitempty"` StatusesURL *string `json:"statuses_url,omitempty"` RepositoryURL *string `json:"repository_url,omitempty"` + NodeID *string `json:"node_id,omitempty"` } // DeploymentRequest represents a deployment request @@ -86,7 +88,7 @@ func (s *RepositoriesService) ListDeployments(ctx context.Context, owner, repo s // GetDeployment returns a single deployment of a repository. // // GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment -func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo string, deploymentID int) (*Deployment, *Response, error) { +func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Deployment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID) req, err := s.client.NewRequest("GET", u, nil) @@ -114,8 +116,9 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when deployment support fully launches - req.Header.Set("Accept", mediaTypeDeploymentStatusPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) d := new(Deployment) resp, err := s.client.Do(ctx, req, d) @@ -129,7 +132,7 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo // DeploymentStatus represents the status of a // particular deployment. type DeploymentStatus struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` // State is the deployment state. // Possible values are: "pending", "success", "failure", "error", "inactive". State *string `json:"state,omitempty"` @@ -140,6 +143,7 @@ type DeploymentStatus struct { UpdatedAt *Timestamp `json:"updated_at,omitempty"` DeploymentURL *string `json:"deployment_url,omitempty"` RepositoryURL *string `json:"repository_url,omitempty"` + NodeID *string `json:"node_id,omitempty"` } // DeploymentStatusRequest represents a deployment request @@ -147,6 +151,7 @@ type DeploymentStatusRequest struct { State *string `json:"state,omitempty"` LogURL *string `json:"log_url,omitempty"` Description *string `json:"description,omitempty"` + Environment *string `json:"environment,omitempty"` EnvironmentURL *string `json:"environment_url,omitempty"` AutoInactive *bool `json:"auto_inactive,omitempty"` } @@ -154,7 +159,7 @@ type DeploymentStatusRequest struct { // ListDeploymentStatuses lists the statuses of a given deployment of a repository. // // GitHub API docs: https://developer.github.com/v3/repos/deployments/#list-deployment-statuses -func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, repo string, deployment int, opt *ListOptions) ([]*DeploymentStatus, *Response, error) { +func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, repo string, deployment int64, opt *ListOptions) ([]*DeploymentStatus, *Response, error) { u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment) u, err := addOptions(u, opt) if err != nil { @@ -178,7 +183,7 @@ func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, // GetDeploymentStatus returns a single deployment status of a repository. // // GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment-status -func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, repo string, deploymentID, deploymentStatusID int) (*DeploymentStatus, *Response, error) { +func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, repo string, deploymentID, deploymentStatusID int64) (*DeploymentStatus, *Response, error) { u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses/%v", owner, repo, deploymentID, deploymentStatusID) req, err := s.client.NewRequest("GET", u, nil) @@ -186,8 +191,9 @@ func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, re return nil, nil, err } - // TODO: remove custom Accept header when deployment support fully launches - req.Header.Set("Accept", mediaTypeDeploymentStatusPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) d := new(DeploymentStatus) resp, err := s.client.Do(ctx, req, d) @@ -201,7 +207,7 @@ func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, re // CreateDeploymentStatus creates a new status for a deployment. // // GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment-status -func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, repo string, deployment int, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) { +func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, repo string, deployment int64, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) { u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment) req, err := s.client.NewRequest("POST", u, request) @@ -209,8 +215,9 @@ func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when deployment support fully launches - req.Header.Set("Accept", mediaTypeDeploymentStatusPreview) + // TODO: remove custom Accept headers when APIs fully launch. + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) d := new(DeploymentStatus) resp, err := s.client.Do(ctx, req, d) diff --git a/vendor/github.com/google/go-github/github/repos_deployments_test.go b/vendor/github.com/google/go-github/github/repos_deployments_test.go index 9fa44b2ba..3396cf44d 100644 --- a/vendor/github.com/google/go-github/github/repos_deployments_test.go +++ b/vendor/github.com/google/go-github/github/repos_deployments_test.go @@ -11,11 +11,12 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" ) func TestRepositoriesService_ListDeployments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments", func(w http.ResponseWriter, r *http.Request) { @@ -30,14 +31,14 @@ func TestRepositoriesService_ListDeployments(t *testing.T) { t.Errorf("Repositories.ListDeployments returned error: %v", err) } - want := []*Deployment{{ID: Int(1)}, {ID: Int(2)}} + want := []*Deployment{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(deployments, want) { t.Errorf("Repositories.ListDeployments returned %+v, want %+v", deployments, want) } } func TestRepositoriesService_GetDeployment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments/3", func(w http.ResponseWriter, r *http.Request) { @@ -50,7 +51,7 @@ func TestRepositoriesService_GetDeployment(t *testing.T) { t.Errorf("Repositories.GetDeployment returned error: %v", err) } - want := &Deployment{ID: Int(3)} + want := &Deployment{ID: Int64(3)} if !reflect.DeepEqual(deployment, want) { t.Errorf("Repositories.GetDeployment returned %+v, want %+v", deployment, want) @@ -58,7 +59,7 @@ func TestRepositoriesService_GetDeployment(t *testing.T) { } func TestRepositoriesService_CreateDeployment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &DeploymentRequest{Ref: String("1111"), Task: String("deploy"), TransientEnvironment: Bool(true)} @@ -68,7 +69,8 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview) + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } @@ -88,7 +90,7 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) { } func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments/1/statuses", func(w http.ResponseWriter, r *http.Request) { @@ -103,19 +105,20 @@ func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) { t.Errorf("Repositories.ListDeploymentStatuses returned error: %v", err) } - want := []*DeploymentStatus{{ID: Int(1)}, {ID: Int(2)}} + want := []*DeploymentStatus{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(statutses, want) { t.Errorf("Repositories.ListDeploymentStatuses returned %+v, want %+v", statutses, want) } } func TestRepositoriesService_GetDeploymentStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} mux.HandleFunc("/repos/o/r/deployments/3/statuses/4", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview) + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) fmt.Fprint(w, `{"id":4}`) }) @@ -124,14 +127,14 @@ func TestRepositoriesService_GetDeploymentStatus(t *testing.T) { t.Errorf("Repositories.GetDeploymentStatus returned error: %v", err) } - want := &DeploymentStatus{ID: Int(4)} + want := &DeploymentStatus{ID: Int64(4)} if !reflect.DeepEqual(deploymentStatus, want) { t.Errorf("Repositories.GetDeploymentStatus returned %+v, want %+v", deploymentStatus, want) } } func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &DeploymentStatusRequest{State: String("inactive"), Description: String("deploy"), AutoInactive: Bool(false)} @@ -141,7 +144,8 @@ func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview) + acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } diff --git a/vendor/github.com/google/go-github/github/repos_forks.go b/vendor/github.com/google/go-github/github/repos_forks.go index 4ca19a42d..bfff27bb9 100644 --- a/vendor/github.com/google/go-github/github/repos_forks.go +++ b/vendor/github.com/google/go-github/github/repos_forks.go @@ -8,6 +8,8 @@ package github import ( "context" "fmt" + + "encoding/json" ) // RepositoryListForksOptions specifies the optional parameters to the @@ -58,7 +60,8 @@ type RepositoryCreateForkOptions struct { // // This method might return an *AcceptedError and a status code of // 202. This is because this is the status that GitHub returns to signify that -// it is now computing creating the fork in a background task. +// it is now computing creating the fork in a background task. In this event, +// the Repository value will be returned, which includes the details about the pending fork. // A follow up request, after a delay of a second or so, should result // in a successful request. // @@ -78,6 +81,14 @@ func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string fork := new(Repository) resp, err := s.client.Do(ctx, req, fork) if err != nil { + // Persist AcceptedError's metadata to the Repository object. + if aerr, ok := err.(*AcceptedError); ok { + if err := json.Unmarshal(aerr.Raw, fork); err != nil { + return fork, resp, err + } + + return fork, resp, err + } return nil, resp, err } diff --git a/vendor/github.com/google/go-github/github/repos_forks_test.go b/vendor/github.com/google/go-github/github/repos_forks_test.go index f9cf1e3a3..065f59273 100644 --- a/vendor/github.com/google/go-github/github/repos_forks_test.go +++ b/vendor/github.com/google/go-github/github/repos_forks_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_ListForks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { @@ -36,19 +36,22 @@ func TestRepositoriesService_ListForks(t *testing.T) { t.Errorf("Repositories.ListForks returned error: %v", err) } - want := []*Repository{{ID: Int(1)}, {ID: Int(2)}} + want := []*Repository{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.ListForks returned %+v, want %+v", repos, want) } } func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListForks(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateFork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { @@ -63,13 +66,40 @@ func TestRepositoriesService_CreateFork(t *testing.T) { t.Errorf("Repositories.CreateFork returned error: %v", err) } - want := &Repository{ID: Int(1)} + want := &Repository{ID: Int64(1)} + if !reflect.DeepEqual(repo, want) { + t.Errorf("Repositories.CreateFork returned %+v, want %+v", repo, want) + } +} + +func TestRepositoriesService_CreateFork_deferred(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testFormValues(t, r, values{"organization": "o"}) + // This response indicates the fork will happen asynchronously. + w.WriteHeader(http.StatusAccepted) + fmt.Fprint(w, `{"id":1}`) + }) + + opt := &RepositoryCreateForkOptions{Organization: "o"} + repo, _, err := client.Repositories.CreateFork(context.Background(), "o", "r", opt) + if _, ok := err.(*AcceptedError); !ok { + t.Errorf("Repositories.CreateFork returned error: %v (want AcceptedError)", err) + } + + want := &Repository{ID: Int64(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.CreateFork returned %+v, want %+v", repo, want) } } func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateFork(context.Background(), "%", "r", nil) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/repos_hooks.go b/vendor/github.com/google/go-github/github/repos_hooks.go index 67ce96ac3..56374b3ec 100644 --- a/vendor/github.com/google/go-github/github/repos_hooks.go +++ b/vendor/github.com/google/go-github/github/repos_hooks.go @@ -69,27 +69,51 @@ func (w WebHookAuthor) String() string { // Hook represents a GitHub (web and service) hook for a repository. type Hook struct { - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - Name *string `json:"name,omitempty"` - URL *string `json:"url,omitempty"` - Events []string `json:"events,omitempty"` - Active *bool `json:"active,omitempty"` - Config map[string]interface{} `json:"config,omitempty"` - ID *int `json:"id,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + URL *string `json:"url,omitempty"` + ID *int64 `json:"id,omitempty"` + + // Only the following fields are used when creating a hook. + // Config is required. + Config map[string]interface{} `json:"config,omitempty"` + Events []string `json:"events,omitempty"` + Active *bool `json:"active,omitempty"` } func (h Hook) String() string { return Stringify(h) } +// createHookRequest is a subset of Hook and is used internally +// by CreateHook to pass only the known fields for the endpoint. +// +// See https://github.com/google/go-github/issues/1015 for more +// information. +type createHookRequest struct { + // Config is required. + Config map[string]interface{} `json:"config,omitempty"` + Events []string `json:"events,omitempty"` + Active *bool `json:"active,omitempty"` +} + // CreateHook creates a Hook for the specified repository. -// Name and Config are required fields. +// Config is a required field. +// +// Note that only a subset of the hook fields are used and hook must +// not be nil. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#create-a-hook func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string, hook *Hook) (*Hook, *Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo) - req, err := s.client.NewRequest("POST", u, hook) + + hookReq := &createHookRequest{ + Events: hook.Events, + Active: hook.Active, + Config: hook.Config, + } + + req, err := s.client.NewRequest("POST", u, hookReq) if err != nil { return nil, nil, err } @@ -130,21 +154,25 @@ func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string, // GetHook returns a single specified Hook. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#get-single-hook -func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int) (*Hook, *Response, error) { +func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int64) (*Hook, *Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - hook := new(Hook) - resp, err := s.client.Do(ctx, req, hook) - return hook, resp, err + h := new(Hook) + resp, err := s.client.Do(ctx, req, h) + if err != nil { + return nil, resp, err + } + + return h, resp, nil } // EditHook updates a specified Hook. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#edit-a-hook -func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int, hook *Hook) (*Hook, *Response, error) { +func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int64, hook *Hook) (*Hook, *Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) req, err := s.client.NewRequest("PATCH", u, hook) if err != nil { @@ -152,13 +180,17 @@ func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, } h := new(Hook) resp, err := s.client.Do(ctx, req, h) - return h, resp, err + if err != nil { + return nil, resp, err + } + + return h, resp, nil } // DeleteHook deletes a specified Hook. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#delete-a-hook -func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -170,7 +202,7 @@ func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string // PingHook triggers a 'ping' event to be sent to the Hook. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#ping-a-hook -func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id) req, err := s.client.NewRequest("POST", u, nil) if err != nil { @@ -182,7 +214,7 @@ func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, // TestHook triggers a test Hook by github. // // GitHub API docs: https://developer.github.com/v3/repos/hooks/#test-a-push-hook -func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id) req, err := s.client.NewRequest("POST", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_hooks_test.go b/vendor/github.com/google/go-github/github/repos_hooks_test.go index 364f4583f..1223b4427 100644 --- a/vendor/github.com/google/go-github/github/repos_hooks_test.go +++ b/vendor/github.com/google/go-github/github/repos_hooks_test.go @@ -15,18 +15,19 @@ import ( ) func TestRepositoriesService_CreateHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &Hook{Name: String("t")} + input := &Hook{CreatedAt: &referenceTime} mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) { - v := new(Hook) + v := new(createHookRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) + want := &createHookRequest{} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) } fmt.Fprint(w, `{"id":1}`) @@ -37,19 +38,14 @@ func TestRepositoriesService_CreateHook(t *testing.T) { t.Errorf("Repositories.CreateHook returned error: %v", err) } - want := &Hook{ID: Int(1)} + want := &Hook{ID: Int64(1)} if !reflect.DeepEqual(hook, want) { t.Errorf("Repositories.CreateHook returned %+v, want %+v", hook, want) } } -func TestRepositoriesService_CreateHook_invalidOwner(t *testing.T) { - _, _, err := client.Repositories.CreateHook(context.Background(), "%", "%", nil) - testURLParseError(t, err) -} - func TestRepositoriesService_ListHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) { @@ -65,19 +61,22 @@ func TestRepositoriesService_ListHooks(t *testing.T) { t.Errorf("Repositories.ListHooks returned error: %v", err) } - want := []*Hook{{ID: Int(1)}, {ID: Int(2)}} + want := []*Hook{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(hooks, want) { t.Errorf("Repositories.ListHooks returned %+v, want %+v", hooks, want) } } func TestRepositoriesService_ListHooks_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListHooks(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -90,22 +89,25 @@ func TestRepositoriesService_GetHook(t *testing.T) { t.Errorf("Repositories.GetHook returned error: %v", err) } - want := &Hook{ID: Int(1)} + want := &Hook{ID: Int64(1)} if !reflect.DeepEqual(hook, want) { t.Errorf("Repositories.GetHook returned %+v, want %+v", hook, want) } } func TestRepositoriesService_GetHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_EditHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &Hook{Name: String("t")} + input := &Hook{} mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) { v := new(Hook) @@ -124,19 +126,22 @@ func TestRepositoriesService_EditHook(t *testing.T) { t.Errorf("Repositories.EditHook returned error: %v", err) } - want := &Hook{ID: Int(1)} + want := &Hook{ID: Int64(1)} if !reflect.DeepEqual(hook, want) { t.Errorf("Repositories.EditHook returned %+v, want %+v", hook, want) } } func TestRepositoriesService_EditHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.EditHook(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -150,12 +155,15 @@ func TestRepositoriesService_DeleteHook(t *testing.T) { } func TestRepositoriesService_DeleteHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_PingHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { @@ -169,7 +177,7 @@ func TestRepositoriesService_PingHook(t *testing.T) { } func TestRepositoriesService_TestHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1/tests", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +191,9 @@ func TestRepositoriesService_TestHook(t *testing.T) { } func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.TestHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/repos_invitations.go b/vendor/github.com/google/go-github/github/repos_invitations.go index 0a2b7c198..34bf3830f 100644 --- a/vendor/github.com/google/go-github/github/repos_invitations.go +++ b/vendor/github.com/google/go-github/github/repos_invitations.go @@ -12,7 +12,7 @@ import ( // RepositoryInvitation represents an invitation to collaborate on a repo. type RepositoryInvitation struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Repo *Repository `json:"repository,omitempty"` Invitee *User `json:"invitee,omitempty"` Inviter *User `json:"inviter,omitempty"` @@ -55,7 +55,7 @@ func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo s // DeleteInvitation deletes a repository invitation. // // GitHub API docs: https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation -func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int) (*Response, error) { +func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -75,7 +75,7 @@ func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo // on the repository. Possible values are: "read", "write", "admin". // // GitHub API docs: https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation -func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int, permissions string) (*RepositoryInvitation, *Response, error) { +func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) { opts := &struct { Permissions string `json:"permissions"` }{Permissions: permissions} diff --git a/vendor/github.com/google/go-github/github/repos_invitations_test.go b/vendor/github.com/google/go-github/github/repos_invitations_test.go index 01ac66657..27bec41db 100644 --- a/vendor/github.com/google/go-github/github/repos_invitations_test.go +++ b/vendor/github.com/google/go-github/github/repos_invitations_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_ListInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations", func(w http.ResponseWriter, r *http.Request) { @@ -30,14 +30,14 @@ func TestRepositoriesService_ListInvitations(t *testing.T) { t.Errorf("Repositories.ListInvitations returned error: %v", err) } - want := []*RepositoryInvitation{{ID: Int(1)}, {ID: Int(2)}} + want := []*RepositoryInvitation{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(got, want) { t.Errorf("Repositories.ListInvitations = %+v, want %+v", got, want) } } func TestRepositoriesService_DeleteInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { @@ -53,7 +53,7 @@ func TestRepositoriesService_DeleteInvitation(t *testing.T) { } func TestRepositoriesService_UpdateInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { @@ -67,7 +67,7 @@ func TestRepositoriesService_UpdateInvitation(t *testing.T) { t.Errorf("Repositories.UpdateInvitation returned error: %v", err) } - want := &RepositoryInvitation{ID: Int(1)} + want := &RepositoryInvitation{ID: Int64(1)} if !reflect.DeepEqual(got, want) { t.Errorf("Repositories.UpdateInvitation = %+v, want %+v", got, want) } diff --git a/vendor/github.com/google/go-github/github/repos_keys.go b/vendor/github.com/google/go-github/github/repos_keys.go index f5a865813..b484f8444 100644 --- a/vendor/github.com/google/go-github/github/repos_keys.go +++ b/vendor/github.com/google/go-github/github/repos_keys.go @@ -39,7 +39,7 @@ func (s *RepositoriesService) ListKeys(ctx context.Context, owner string, repo s // GetKey fetches a single deploy key. // // GitHub API docs: https://developer.github.com/v3/repos/keys/#get -func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo string, id int) (*Key, *Response, error) { +func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo string, id int64) (*Key, *Response, error) { u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) @@ -79,7 +79,7 @@ func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo // EditKey edits a deploy key. // // GitHub API docs: https://developer.github.com/v3/repos/keys/#edit -func (s *RepositoriesService) EditKey(ctx context.Context, owner string, repo string, id int, key *Key) (*Key, *Response, error) { +func (s *RepositoriesService) EditKey(ctx context.Context, owner string, repo string, id int64, key *Key) (*Key, *Response, error) { u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id) req, err := s.client.NewRequest("PATCH", u, key) @@ -99,7 +99,7 @@ func (s *RepositoriesService) EditKey(ctx context.Context, owner string, repo st // DeleteKey deletes a deploy key. // // GitHub API docs: https://developer.github.com/v3/repos/keys/#delete -func (s *RepositoriesService) DeleteKey(ctx context.Context, owner string, repo string, id int) (*Response, error) { +func (s *RepositoriesService) DeleteKey(ctx context.Context, owner string, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id) req, err := s.client.NewRequest("DELETE", u, nil) diff --git a/vendor/github.com/google/go-github/github/repos_keys_test.go b/vendor/github.com/google/go-github/github/repos_keys_test.go index 2ef04fdcb..75a17356e 100644 --- a/vendor/github.com/google/go-github/github/repos_keys_test.go +++ b/vendor/github.com/google/go-github/github/repos_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListKeys(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) { @@ -30,19 +30,22 @@ func TestRepositoriesService_ListKeys(t *testing.T) { t.Errorf("Repositories.ListKeys returned error: %v", err) } - want := []*Key{{ID: Int(1)}} + want := []*Key{{ID: Int64(1)}} if !reflect.DeepEqual(keys, want) { t.Errorf("Repositories.ListKeys returned %+v, want %+v", keys, want) } } func TestRepositoriesService_ListKeys_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListKeys(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -55,19 +58,22 @@ func TestRepositoriesService_GetKey(t *testing.T) { t.Errorf("Repositories.GetKey returned error: %v", err) } - want := &Key{ID: Int(1)} + want := &Key{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Repositories.GetKey returned %+v, want %+v", key, want) } } func TestRepositoriesService_GetKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetKey(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_CreateKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -89,19 +95,22 @@ func TestRepositoriesService_CreateKey(t *testing.T) { t.Errorf("Repositories.GetKey returned error: %v", err) } - want := &Key{ID: Int(1)} + want := &Key{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Repositories.GetKey returned %+v, want %+v", key, want) } } func TestRepositoriesService_CreateKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateKey(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_EditKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -123,19 +132,22 @@ func TestRepositoriesService_EditKey(t *testing.T) { t.Errorf("Repositories.EditKey returned error: %v", err) } - want := &Key{ID: Int(1)} + want := &Key{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Repositories.EditKey returned %+v, want %+v", key, want) } } func TestRepositoriesService_EditKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.EditKey(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -149,6 +161,9 @@ func TestRepositoriesService_DeleteKey(t *testing.T) { } func TestRepositoriesService_DeleteKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteKey(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/repos_merging_test.go b/vendor/github.com/google/go-github/github/repos_merging_test.go index e2e264fd6..086f24bbc 100644 --- a/vendor/github.com/google/go-github/github/repos_merging_test.go +++ b/vendor/github.com/google/go-github/github/repos_merging_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_Merge(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryMergeRequest{ diff --git a/vendor/github.com/google/go-github/github/repos_pages.go b/vendor/github.com/google/go-github/github/repos_pages.go index 075f5742d..94a95f2b8 100644 --- a/vendor/github.com/google/go-github/github/repos_pages.go +++ b/vendor/github.com/google/go-github/github/repos_pages.go @@ -104,7 +104,7 @@ func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, re // GetPageBuild fetches the specific build information for a GitHub pages site. // // GitHub API docs: https://developer.github.com/v3/repos/pages/#list-a-specific-pages-build -func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int) (*PagesBuild, *Response, error) { +func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int64) (*PagesBuild, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pages/builds/%v", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_pages_test.go b/vendor/github.com/google/go-github/github/repos_pages_test.go index c9e19a1f5..21a00f9dd 100644 --- a/vendor/github.com/google/go-github/github/repos_pages_test.go +++ b/vendor/github.com/google/go-github/github/repos_pages_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_GetPagesInfo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { @@ -35,7 +35,7 @@ func TestRepositoriesService_GetPagesInfo(t *testing.T) { } func TestRepositoriesService_ListPagesBuilds(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { @@ -55,7 +55,7 @@ func TestRepositoriesService_ListPagesBuilds(t *testing.T) { } func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +73,7 @@ func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) { } func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds/latest", func(w http.ResponseWriter, r *http.Request) { @@ -93,7 +93,7 @@ func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) { } func TestRepositoriesService_GetPageBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds/1", func(w http.ResponseWriter, r *http.Request) { @@ -113,7 +113,7 @@ func TestRepositoriesService_GetPageBuild(t *testing.T) { } func TestRepositoriesService_RequestPageBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/repos_prereceive_hooks.go b/vendor/github.com/google/go-github/github/repos_prereceive_hooks.go new file mode 100644 index 000000000..cab09f747 --- /dev/null +++ b/vendor/github.com/google/go-github/github/repos_prereceive_hooks.go @@ -0,0 +1,110 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// PreReceiveHook represents a GitHub pre-receive hook for a repository. +type PreReceiveHook struct { + ID *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Enforcement *string `json:"enforcement,omitempty"` + ConfigURL *string `json:"configuration_url,omitempty"` +} + +func (p PreReceiveHook) String() string { + return Stringify(p) +} + +// ListPreReceiveHooks lists all pre-receive hooks for the specified repository. +// +// GitHub API docs: https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/#list-pre-receive-hooks +func (s *RepositoriesService) ListPreReceiveHooks(ctx context.Context, owner, repo string, opt *ListOptions) ([]*PreReceiveHook, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks", owner, repo) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) + + var hooks []*PreReceiveHook + resp, err := s.client.Do(ctx, req, &hooks) + if err != nil { + return nil, resp, err + } + + return hooks, resp, nil +} + +// GetPreReceiveHook returns a single specified pre-receive hook. +// +// GitHub API docs: https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/#get-a-single-pre-receive-hook +func (s *RepositoriesService) GetPreReceiveHook(ctx context.Context, owner, repo string, id int64) (*PreReceiveHook, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) + + h := new(PreReceiveHook) + resp, err := s.client.Do(ctx, req, h) + if err != nil { + return nil, resp, err + } + + return h, resp, nil +} + +// UpdatePreReceiveHook updates a specified pre-receive hook. +// +// GitHub API docs: https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/#update-pre-receive-hook-enforcement +func (s *RepositoriesService) UpdatePreReceiveHook(ctx context.Context, owner, repo string, id int64, hook *PreReceiveHook) (*PreReceiveHook, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id) + req, err := s.client.NewRequest("PATCH", u, hook) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) + + h := new(PreReceiveHook) + resp, err := s.client.Do(ctx, req, h) + if err != nil { + return nil, resp, err + } + + return h, resp, nil +} + +// DeletePreReceiveHook deletes a specified pre-receive hook. +// +// GitHub API docs: https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/#remove-enforcement-overrides-for-a-pre-receive-hook +func (s *RepositoriesService) DeletePreReceiveHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/repos_prereceive_hooks_test.go b/vendor/github.com/google/go-github/github/repos_prereceive_hooks_test.go new file mode 100644 index 000000000..43ff6146d --- /dev/null +++ b/vendor/github.com/google/go-github/github/repos_prereceive_hooks_test.go @@ -0,0 +1,135 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestRepositoriesService_ListPreReceiveHooks(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/pre-receive-hooks", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypePreReceiveHooksPreview) + testFormValues(t, r, values{"page": "2"}) + fmt.Fprint(w, `[{"id":1}, {"id":2}]`) + }) + + opt := &ListOptions{Page: 2} + + hooks, _, err := client.Repositories.ListPreReceiveHooks(context.Background(), "o", "r", opt) + if err != nil { + t.Errorf("Repositories.ListHooks returned error: %v", err) + } + + want := []*PreReceiveHook{{ID: Int64(1)}, {ID: Int64(2)}} + if !reflect.DeepEqual(hooks, want) { + t.Errorf("Repositories.ListPreReceiveHooks returned %+v, want %+v", hooks, want) + } +} + +func TestRepositoriesService_ListPreReceiveHooks_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Repositories.ListPreReceiveHooks(context.Background(), "%", "%", nil) + testURLParseError(t, err) +} + +func TestRepositoriesService_GetPreReceiveHook(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/pre-receive-hooks/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypePreReceiveHooksPreview) + fmt.Fprint(w, `{"id":1}`) + }) + + hook, _, err := client.Repositories.GetPreReceiveHook(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("Repositories.GetPreReceiveHook returned error: %v", err) + } + + want := &PreReceiveHook{ID: Int64(1)} + if !reflect.DeepEqual(hook, want) { + t.Errorf("Repositories.GetPreReceiveHook returned %+v, want %+v", hook, want) + } +} + +func TestRepositoriesService_GetPreReceiveHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Repositories.GetPreReceiveHook(context.Background(), "%", "%", 1) + testURLParseError(t, err) +} + +func TestRepositoriesService_UpdatePreReceiveHook(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &PreReceiveHook{} + + mux.HandleFunc("/repos/o/r/pre-receive-hooks/1", func(w http.ResponseWriter, r *http.Request) { + v := new(PreReceiveHook) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + hook, _, err := client.Repositories.UpdatePreReceiveHook(context.Background(), "o", "r", 1, input) + if err != nil { + t.Errorf("Repositories.UpdatePreReceiveHook returned error: %v", err) + } + + want := &PreReceiveHook{ID: Int64(1)} + if !reflect.DeepEqual(hook, want) { + t.Errorf("Repositories.UpdatePreReceiveHook returned %+v, want %+v", hook, want) + } +} + +func TestRepositoriesService_PreReceiveHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Repositories.UpdatePreReceiveHook(context.Background(), "%", "%", 1, nil) + testURLParseError(t, err) +} + +func TestRepositoriesService_DeletePreReceiveHook(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/pre-receive-hooks/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + _, err := client.Repositories.DeletePreReceiveHook(context.Background(), "o", "r", 1) + if err != nil { + t.Errorf("Repositories.DeletePreReceiveHook returned error: %v", err) + } +} + +func TestRepositoriesService_DeletePreReceiveHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, err := client.Repositories.DeletePreReceiveHook(context.Background(), "%", "%", 1) + testURLParseError(t, err) +} diff --git a/vendor/github.com/google/go-github/github/repos_projects.go b/vendor/github.com/google/go-github/github/repos_projects.go index 770ffc76f..d6486d293 100644 --- a/vendor/github.com/google/go-github/github/repos_projects.go +++ b/vendor/github.com/google/go-github/github/repos_projects.go @@ -34,7 +34,7 @@ func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) var projects []*Project @@ -56,7 +56,7 @@ func (s *RepositoriesService) CreateProject(ctx context.Context, owner, repo str return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. + // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeProjectsPreview) project := &Project{} diff --git a/vendor/github.com/google/go-github/github/repos_projects_test.go b/vendor/github.com/google/go-github/github/repos_projects_test.go index 57dbdd1b3..2d54eaa10 100644 --- a/vendor/github.com/google/go-github/github/repos_projects_test.go +++ b/vendor/github.com/google/go-github/github/repos_projects_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListProjects(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/projects", func(w http.ResponseWriter, r *http.Request) { @@ -31,17 +31,17 @@ func TestRepositoriesService_ListProjects(t *testing.T) { t.Errorf("Repositories.ListProjects returned error: %v", err) } - want := []*Project{{ID: Int(1)}} + want := []*Project{{ID: Int64(1)}} if !reflect.DeepEqual(projects, want) { t.Errorf("Repositories.ListProjects returned %+v, want %+v", projects, want) } } func TestRepositoriesService_CreateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &ProjectOptions{Name: "Project Name", Body: "Project body."} + input := &ProjectOptions{Name: String("Project Name"), Body: String("Project body.")} mux.HandleFunc("/repos/o/r/projects", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -61,7 +61,7 @@ func TestRepositoriesService_CreateProject(t *testing.T) { t.Errorf("Repositories.CreateProject returned error: %v", err) } - want := &Project{ID: Int(1)} + want := &Project{ID: Int64(1)} if !reflect.DeepEqual(project, want) { t.Errorf("Repositories.CreateProject returned %+v, want %+v", project, want) } diff --git a/vendor/github.com/google/go-github/github/repos_releases.go b/vendor/github.com/google/go-github/github/repos_releases.go index 1ee7ecf99..bf58743eb 100644 --- a/vendor/github.com/google/go-github/github/repos_releases.go +++ b/vendor/github.com/google/go-github/github/repos_releases.go @@ -19,23 +19,26 @@ import ( // RepositoryRelease represents a GitHub release in a repository. type RepositoryRelease struct { - ID *int `json:"id,omitempty"` - TagName *string `json:"tag_name,omitempty"` - TargetCommitish *string `json:"target_commitish,omitempty"` - Name *string `json:"name,omitempty"` - Body *string `json:"body,omitempty"` - Draft *bool `json:"draft,omitempty"` - Prerelease *bool `json:"prerelease,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - PublishedAt *Timestamp `json:"published_at,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - AssetsURL *string `json:"assets_url,omitempty"` - Assets []ReleaseAsset `json:"assets,omitempty"` - UploadURL *string `json:"upload_url,omitempty"` - ZipballURL *string `json:"zipball_url,omitempty"` - TarballURL *string `json:"tarball_url,omitempty"` - Author *User `json:"author,omitempty"` + TagName *string `json:"tag_name,omitempty"` + TargetCommitish *string `json:"target_commitish,omitempty"` + Name *string `json:"name,omitempty"` + Body *string `json:"body,omitempty"` + Draft *bool `json:"draft,omitempty"` + Prerelease *bool `json:"prerelease,omitempty"` + + // The following fields are not used in CreateRelease or EditRelease: + ID *int64 `json:"id,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + PublishedAt *Timestamp `json:"published_at,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + AssetsURL *string `json:"assets_url,omitempty"` + Assets []ReleaseAsset `json:"assets,omitempty"` + UploadURL *string `json:"upload_url,omitempty"` + ZipballURL *string `json:"zipball_url,omitempty"` + TarballURL *string `json:"tarball_url,omitempty"` + Author *User `json:"author,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (r RepositoryRelease) String() string { @@ -44,7 +47,7 @@ func (r RepositoryRelease) String() string { // ReleaseAsset represents a GitHub release asset in a repository. type ReleaseAsset struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` Name *string `json:"name,omitempty"` Label *string `json:"label,omitempty"` @@ -56,6 +59,7 @@ type ReleaseAsset struct { UpdatedAt *Timestamp `json:"updated_at,omitempty"` BrowserDownloadURL *string `json:"browser_download_url,omitempty"` Uploader *User `json:"uploader,omitempty"` + NodeID *string `json:"node_id,omitempty"` } func (r ReleaseAsset) String() string { @@ -88,7 +92,7 @@ func (s *RepositoriesService) ListReleases(ctx context.Context, owner, repo stri // GetRelease fetches a single release. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-single-release -func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string, id int) (*RepositoryRelease, *Response, error) { +func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string, id int64) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) return s.getSingleRelease(ctx, u) } @@ -123,13 +127,40 @@ func (s *RepositoriesService) getSingleRelease(ctx context.Context, url string) return release, resp, nil } +// repositoryReleaseRequest is a subset of RepositoryRelease and +// is used internally by CreateRelease and EditRelease to pass +// only the known fields for these endpoints. +// +// See https://github.com/google/go-github/issues/992 for more +// information. +type repositoryReleaseRequest struct { + TagName *string `json:"tag_name,omitempty"` + TargetCommitish *string `json:"target_commitish,omitempty"` + Name *string `json:"name,omitempty"` + Body *string `json:"body,omitempty"` + Draft *bool `json:"draft,omitempty"` + Prerelease *bool `json:"prerelease,omitempty"` +} + // CreateRelease adds a new release for a repository. // +// Note that only a subset of the release fields are used. +// See RepositoryRelease for more information. +// // GitHub API docs: https://developer.github.com/v3/repos/releases/#create-a-release func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases", owner, repo) - req, err := s.client.NewRequest("POST", u, release) + releaseReq := &repositoryReleaseRequest{ + TagName: release.TagName, + TargetCommitish: release.TargetCommitish, + Name: release.Name, + Body: release.Body, + Draft: release.Draft, + Prerelease: release.Prerelease, + } + + req, err := s.client.NewRequest("POST", u, releaseReq) if err != nil { return nil, nil, err } @@ -144,11 +175,23 @@ func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo str // EditRelease edits a repository release. // +// Note that only a subset of the release fields are used. +// See RepositoryRelease for more information. +// // GitHub API docs: https://developer.github.com/v3/repos/releases/#edit-a-release -func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { +func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int64, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) - req, err := s.client.NewRequest("PATCH", u, release) + releaseReq := &repositoryReleaseRequest{ + TagName: release.TagName, + TargetCommitish: release.TargetCommitish, + Name: release.Name, + Body: release.Body, + Draft: release.Draft, + Prerelease: release.Prerelease, + } + + req, err := s.client.NewRequest("PATCH", u, releaseReq) if err != nil { return nil, nil, err } @@ -164,7 +207,7 @@ func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo strin // DeleteRelease delete a single release from a repository. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#delete-a-release -func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) req, err := s.client.NewRequest("DELETE", u, nil) @@ -177,7 +220,7 @@ func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo str // ListReleaseAssets lists the release's assets. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#list-assets-for-a-release -func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*ReleaseAsset, *Response, error) { +func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int64, opt *ListOptions) ([]*ReleaseAsset, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id) u, err := addOptions(u, opt) if err != nil { @@ -200,7 +243,7 @@ func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo // GetReleaseAsset fetches a single release asset. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-single-release-asset -func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo string, id int) (*ReleaseAsset, *Response, error) { +func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo string, id int64) (*ReleaseAsset, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) @@ -224,7 +267,7 @@ func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo s // of the io.ReadCloser. Exactly one of rc and redirectURL will be zero. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-single-release-asset -func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int) (rc io.ReadCloser, redirectURL string, err error) { +func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64) (rc io.ReadCloser, redirectURL string, err error) { u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) req, err := s.client.NewRequest("GET", u, nil) @@ -264,7 +307,7 @@ func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, r // EditReleaseAsset edits a repository release asset. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#edit-a-release-asset -func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo string, id int, release *ReleaseAsset) (*ReleaseAsset, *Response, error) { +func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo string, id int64, release *ReleaseAsset) (*ReleaseAsset, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) req, err := s.client.NewRequest("PATCH", u, release) @@ -283,7 +326,7 @@ func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo // DeleteReleaseAsset delete a single release asset from a repository. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#delete-a-release-asset -func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int) (*Response, error) { +func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int64) (*Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) req, err := s.client.NewRequest("DELETE", u, nil) @@ -297,7 +340,7 @@ func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, rep // To upload assets that cannot be represented by an os.File, call NewUploadRequest directly. // // GitHub API docs: https://developer.github.com/v3/repos/releases/#upload-a-release-asset -func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int, opt *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) { +func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int64, opt *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id) u, err := addOptions(u, opt) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_releases_test.go b/vendor/github.com/google/go-github/github/repos_releases_test.go index 9a2c4c8af..d9a933241 100644 --- a/vendor/github.com/google/go-github/github/repos_releases_test.go +++ b/vendor/github.com/google/go-github/github/repos_releases_test.go @@ -19,7 +19,7 @@ import ( ) func TestRepositoriesService_ListReleases(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { @@ -33,14 +33,14 @@ func TestRepositoriesService_ListReleases(t *testing.T) { if err != nil { t.Errorf("Repositories.ListReleases returned error: %v", err) } - want := []*RepositoryRelease{{ID: Int(1)}} + want := []*RepositoryRelease{{ID: Int64(1)}} if !reflect.DeepEqual(releases, want) { t.Errorf("Repositories.ListReleases returned %+v, want %+v", releases, want) } } func TestRepositoriesService_GetRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { @@ -53,14 +53,14 @@ func TestRepositoriesService_GetRelease(t *testing.T) { t.Errorf("Repositories.GetRelease returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Int(1), Author: &User{Login: String("l")}} + want := &RepositoryRelease{ID: Int64(1), Author: &User{Login: String("l")}} if !reflect.DeepEqual(release, want) { t.Errorf("Repositories.GetRelease returned %+v, want %+v", release, want) } } func TestRepositoriesService_GetLatestRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/latest", func(w http.ResponseWriter, r *http.Request) { @@ -73,14 +73,14 @@ func TestRepositoriesService_GetLatestRelease(t *testing.T) { t.Errorf("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Int(3)} + want := &RepositoryRelease{ID: Int64(3)} if !reflect.DeepEqual(release, want) { t.Errorf("Repositories.GetLatestRelease returned %+v, want %+v", release, want) } } func TestRepositoriesService_GetReleaseByTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/tags/foo", func(w http.ResponseWriter, r *http.Request) { @@ -93,25 +93,41 @@ func TestRepositoriesService_GetReleaseByTag(t *testing.T) { t.Errorf("Repositories.GetReleaseByTag returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Int(13)} + want := &RepositoryRelease{ID: Int64(13)} if !reflect.DeepEqual(release, want) { t.Errorf("Repositories.GetReleaseByTag returned %+v, want %+v", release, want) } } func TestRepositoriesService_CreateRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &RepositoryRelease{Name: String("v1.0")} + input := &RepositoryRelease{ + Name: String("v1.0"), + // Fields to be removed: + ID: Int64(2), + CreatedAt: &Timestamp{referenceTime}, + PublishedAt: &Timestamp{referenceTime}, + URL: String("http://url/"), + HTMLURL: String("http://htmlurl/"), + AssetsURL: String("http://assetsurl/"), + Assets: []ReleaseAsset{{ID: Int64(5)}}, + UploadURL: String("http://uploadurl/"), + ZipballURL: String("http://zipballurl/"), + TarballURL: String("http://tarballurl/"), + Author: &User{Name: String("octocat")}, + NodeID: String("nodeid"), + } mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { - v := new(RepositoryRelease) + v := new(repositoryReleaseRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) + want := &repositoryReleaseRequest{Name: String("v1.0")} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) } fmt.Fprint(w, `{"id":1}`) }) @@ -121,25 +137,41 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { t.Errorf("Repositories.CreateRelease returned error: %v", err) } - want := &RepositoryRelease{ID: Int(1)} + want := &RepositoryRelease{ID: Int64(1)} if !reflect.DeepEqual(release, want) { t.Errorf("Repositories.CreateRelease returned %+v, want %+v", release, want) } } func TestRepositoriesService_EditRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &RepositoryRelease{Name: String("n")} + input := &RepositoryRelease{ + Name: String("n"), + // Fields to be removed: + ID: Int64(2), + CreatedAt: &Timestamp{referenceTime}, + PublishedAt: &Timestamp{referenceTime}, + URL: String("http://url/"), + HTMLURL: String("http://htmlurl/"), + AssetsURL: String("http://assetsurl/"), + Assets: []ReleaseAsset{{ID: Int64(5)}}, + UploadURL: String("http://uploadurl/"), + ZipballURL: String("http://zipballurl/"), + TarballURL: String("http://tarballurl/"), + Author: &User{Name: String("octocat")}, + NodeID: String("nodeid"), + } mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { - v := new(RepositoryRelease) + v := new(repositoryReleaseRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PATCH") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) + want := &repositoryReleaseRequest{Name: String("n")} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) } fmt.Fprint(w, `{"id":1}`) }) @@ -148,14 +180,14 @@ func TestRepositoriesService_EditRelease(t *testing.T) { if err != nil { t.Errorf("Repositories.EditRelease returned error: %v", err) } - want := &RepositoryRelease{ID: Int(1)} + want := &RepositoryRelease{ID: Int64(1)} if !reflect.DeepEqual(release, want) { t.Errorf("Repositories.EditRelease returned = %+v, want %+v", release, want) } } func TestRepositoriesService_DeleteRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { @@ -169,7 +201,7 @@ func TestRepositoriesService_DeleteRelease(t *testing.T) { } func TestRepositoriesService_ListReleaseAssets(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) { @@ -183,14 +215,14 @@ func TestRepositoriesService_ListReleaseAssets(t *testing.T) { if err != nil { t.Errorf("Repositories.ListReleaseAssets returned error: %v", err) } - want := []*ReleaseAsset{{ID: Int(1)}} + want := []*ReleaseAsset{{ID: Int64(1)}} if !reflect.DeepEqual(assets, want) { t.Errorf("Repositories.ListReleaseAssets returned %+v, want %+v", assets, want) } } func TestRepositoriesService_GetReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -202,14 +234,14 @@ func TestRepositoriesService_GetReleaseAsset(t *testing.T) { if err != nil { t.Errorf("Repositories.GetReleaseAsset returned error: %v", err) } - want := &ReleaseAsset{ID: Int(1)} + want := &ReleaseAsset{ID: Int64(1)} if !reflect.DeepEqual(asset, want) { t.Errorf("Repositories.GetReleaseAsset returned %+v, want %+v", asset, want) } } func TestRepositoriesService_DownloadReleaseAsset_Stream(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -235,7 +267,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Stream(t *testing.T) { } func TestRepositoriesService_DownloadReleaseAsset_Redirect(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -255,7 +287,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Redirect(t *testing.T) { } func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -281,7 +313,7 @@ func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) { } func TestRepositoriesService_EditReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ReleaseAsset{Name: String("n")} @@ -301,14 +333,14 @@ func TestRepositoriesService_EditReleaseAsset(t *testing.T) { if err != nil { t.Errorf("Repositories.EditReleaseAsset returned error: %v", err) } - want := &ReleaseAsset{ID: Int(1)} + want := &ReleaseAsset{ID: Int64(1)} if !reflect.DeepEqual(asset, want) { t.Errorf("Repositories.EditReleaseAsset returned = %+v, want %+v", asset, want) } } func TestRepositoriesService_DeleteReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -322,7 +354,7 @@ func TestRepositoriesService_DeleteReleaseAsset(t *testing.T) { } func TestRepositoriesService_UploadReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) { @@ -346,7 +378,7 @@ func TestRepositoriesService_UploadReleaseAsset(t *testing.T) { if err != nil { t.Errorf("Repositories.UploadReleaseAssert returned error: %v", err) } - want := &ReleaseAsset{ID: Int(1)} + want := &ReleaseAsset{ID: Int64(1)} if !reflect.DeepEqual(asset, want) { t.Errorf("Repositories.UploadReleaseAssert returned %+v, want %+v", asset, want) } diff --git a/vendor/github.com/google/go-github/github/repos_stats.go b/vendor/github.com/google/go-github/github/repos_stats.go index 30fc7bd34..bb355aead 100644 --- a/vendor/github.com/google/go-github/github/repos_stats.go +++ b/vendor/github.com/google/go-github/github/repos_stats.go @@ -182,7 +182,7 @@ func (s *RepositoriesService) ListParticipation(ctx context.Context, owner, repo } // PunchCard represents the number of commits made during a given hour of a -// day of thew eek. +// day of the week. type PunchCard struct { Day *int // Day of the week (0-6: =Sunday - Saturday). Hour *int // Hour of day (0-23). diff --git a/vendor/github.com/google/go-github/github/repos_stats_test.go b/vendor/github.com/google/go-github/github/repos_stats_test.go index 1da94d013..055504d70 100644 --- a/vendor/github.com/google/go-github/github/repos_stats_test.go +++ b/vendor/github.com/google/go-github/github/repos_stats_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListContributorsStats(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/contributors", func(w http.ResponseWriter, r *http.Request) { @@ -49,12 +49,12 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) { want := []*ContributorStats{ { Author: &Contributor{ - ID: Int(1), + ID: Int64(1), }, Total: Int(135), Weeks: []WeeklyStats{ { - Week: &Timestamp{time.Date(2013, 05, 05, 00, 00, 00, 0, time.UTC).Local()}, + Week: &Timestamp{time.Date(2013, time.May, 05, 00, 00, 00, 0, time.UTC).Local()}, Additions: Int(6898), Deletions: Int(77), Commits: Int(10), @@ -69,7 +69,7 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) { } func TestRepositoriesService_ListCommitActivity(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/commit_activity", func(w http.ResponseWriter, r *http.Request) { @@ -95,7 +95,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) { { Days: []int{0, 3, 26, 20, 39, 1, 0}, Total: Int(89), - Week: &Timestamp{time.Date(2012, 05, 06, 05, 00, 00, 0, time.UTC).Local()}, + Week: &Timestamp{time.Date(2012, time.May, 06, 05, 00, 00, 0, time.UTC).Local()}, }, } @@ -105,7 +105,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) { } func TestRepositoriesService_ListCodeFrequency(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/code_frequency", func(w http.ResponseWriter, r *http.Request) { @@ -120,7 +120,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) { } want := []*WeeklyStats{{ - Week: &Timestamp{time.Date(2011, 04, 17, 00, 00, 00, 0, time.UTC).Local()}, + Week: &Timestamp{time.Date(2011, time.April, 17, 00, 00, 00, 0, time.UTC).Local()}, Additions: Int(1124), Deletions: Int(-435), }} @@ -131,7 +131,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) { } func TestRepositoriesService_Participation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/participation", func(w http.ResponseWriter, r *http.Request) { @@ -181,7 +181,7 @@ func TestRepositoriesService_Participation(t *testing.T) { } func TestRepositoriesService_ListPunchCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/punch_card", func(w http.ResponseWriter, r *http.Request) { @@ -209,3 +209,28 @@ func TestRepositoriesService_ListPunchCard(t *testing.T) { t.Errorf("RepositoriesService.ListPunchCard returned %+v, want %+v", card, want) } } + +func TestRepositoriesService_AcceptedError(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/stats/contributors", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + // This response indicates the fork will happen asynchronously. + w.WriteHeader(http.StatusAccepted) + fmt.Fprint(w, `{"id":1}`) + }) + + stats, _, err := client.Repositories.ListContributorsStats(context.Background(), "o", "r") + if err == nil { + t.Errorf("RepositoriesService.AcceptedError should have returned an error") + } + + if _, ok := err.(*AcceptedError); !ok { + t.Errorf("RepositoriesService.AcceptedError returned an AcceptedError: %v", err) + } + + if stats != nil { + t.Errorf("RepositoriesService.AcceptedError expected stats to be nil: %v", stats) + } +} diff --git a/vendor/github.com/google/go-github/github/repos_statuses.go b/vendor/github.com/google/go-github/github/repos_statuses.go index 6db501076..f94fdc858 100644 --- a/vendor/github.com/google/go-github/github/repos_statuses.go +++ b/vendor/github.com/google/go-github/github/repos_statuses.go @@ -13,7 +13,7 @@ import ( // RepoStatus represents the status of a repository at a particular reference. type RepoStatus struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` // State is the current state of the repository. Possible values are: diff --git a/vendor/github.com/google/go-github/github/repos_statuses_test.go b/vendor/github.com/google/go-github/github/repos_statuses_test.go index 8e6c9378d..b556b7166 100644 --- a/vendor/github.com/google/go-github/github/repos_statuses_test.go +++ b/vendor/github.com/google/go-github/github/repos_statuses_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListStatuses(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/r/statuses", func(w http.ResponseWriter, r *http.Request) { @@ -30,19 +30,22 @@ func TestRepositoriesService_ListStatuses(t *testing.T) { t.Errorf("Repositories.ListStatuses returned error: %v", err) } - want := []*RepoStatus{{ID: Int(1)}} + want := []*RepoStatus{{ID: Int64(1)}} if !reflect.DeepEqual(statuses, want) { t.Errorf("Repositories.ListStatuses returned %+v, want %+v", statuses, want) } } func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListStatuses(context.Background(), "%", "r", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepoStatus{State: String("s"), TargetURL: String("t"), Description: String("d")} @@ -63,19 +66,22 @@ func TestRepositoriesService_CreateStatus(t *testing.T) { t.Errorf("Repositories.CreateStatus returned error: %v", err) } - want := &RepoStatus{ID: Int(1)} + want := &RepoStatus{ID: Int64(1)} if !reflect.DeepEqual(status, want) { t.Errorf("Repositories.CreateStatus returned %+v, want %+v", status, want) } } func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateStatus(context.Background(), "%", "r", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_GetCombinedStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/r/status", func(w http.ResponseWriter, r *http.Request) { @@ -90,7 +96,7 @@ func TestRepositoriesService_GetCombinedStatus(t *testing.T) { t.Errorf("Repositories.GetCombinedStatus returned error: %v", err) } - want := &CombinedStatus{State: String("success"), Statuses: []RepoStatus{{ID: Int(1)}}} + want := &CombinedStatus{State: String("success"), Statuses: []RepoStatus{{ID: Int64(1)}}} if !reflect.DeepEqual(status, want) { t.Errorf("Repositories.GetCombinedStatus returned %+v, want %+v", status, want) } diff --git a/vendor/github.com/google/go-github/github/repos_test.go b/vendor/github.com/google/go-github/github/repos_test.go index 1f7b424f2..4109eda93 100644 --- a/vendor/github.com/google/go-github/github/repos_test.go +++ b/vendor/github.com/google/go-github/github/repos_test.go @@ -16,10 +16,10 @@ import ( ) func TestRepositoriesService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) @@ -31,17 +31,17 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { t.Errorf("Repositories.List returned error: %v", err) } - want := []*Repository{{ID: Int(1)}, {ID: Int(2)}} + want := []*Repository{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.List returned %+v, want %+v", repos, want) } } func TestRepositoriesService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) @@ -67,17 +67,17 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) { t.Errorf("Repositories.List returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.List returned %+v, want %+v", repos, want) } } func TestRepositoriesService_List_specifiedUser_type(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) @@ -95,22 +95,25 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) { t.Errorf("Repositories.List returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.List returned %+v, want %+v", repos, want) } } func TestRepositoriesService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListByOrg(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) @@ -127,56 +130,61 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { t.Errorf("Repositories.ListByOrg returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.ListByOrg returned %+v, want %+v", repos, want) } } func TestRepositoriesService_ListByOrg_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListByOrg(context.Background(), "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repositories", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "since": "1", - "page": "2", - "per_page": "3", + "since": "1", }) fmt.Fprint(w, `[{"id":1}]`) }) - opt := &RepositoryListAllOptions{1, ListOptions{2, 3}} + opt := &RepositoryListAllOptions{1} repos, _, err := client.Repositories.ListAll(context.Background(), opt) if err != nil { t.Errorf("Repositories.ListAll returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} + want := []*Repository{{ID: Int64(1)}} if !reflect.DeepEqual(repos, want) { t.Errorf("Repositories.ListAll returned %+v, want %+v", repos, want) } } func TestRepositoriesService_Create_user(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &Repository{Name: String("n")} + input := &Repository{ + Name: String("n"), + Archived: Bool(true), // not passed along. + } mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) { - v := new(Repository) + v := new(createRepoRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) + want := &createRepoRequest{Name: String("n")} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) } fmt.Fprint(w, `{"id":1}`) @@ -187,25 +195,29 @@ func TestRepositoriesService_Create_user(t *testing.T) { t.Errorf("Repositories.Create returned error: %v", err) } - want := &Repository{ID: Int(1)} + want := &Repository{ID: Int64(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.Create returned %+v, want %+v", repo, want) } } func TestRepositoriesService_Create_org(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - input := &Repository{Name: String("n")} + input := &Repository{ + Name: String("n"), + Archived: Bool(true), // not passed along. + } mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { - v := new(Repository) + v := new(createRepoRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) + want := &createRepoRequest{Name: String("n")} + if !reflect.DeepEqual(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) } fmt.Fprint(w, `{"id":1}`) @@ -216,22 +228,17 @@ func TestRepositoriesService_Create_org(t *testing.T) { t.Errorf("Repositories.Create returned error: %v", err) } - want := &Repository{ID: Int(1)} + want := &Repository{ID: Int64(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.Create returned %+v, want %+v", repo, want) } } -func TestRepositoriesService_Create_invalidOrg(t *testing.T) { - _, _, err := client.Repositories.Create(context.Background(), "%", nil) - testURLParseError(t, err) -} - func TestRepositoriesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} + acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) @@ -243,14 +250,14 @@ func TestRepositoriesService_Get(t *testing.T) { t.Errorf("Repositories.Get returned error: %v", err) } - want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} + want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.Get returned %+v, want %+v", repo, want) } } func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/community/code_of_conduct", func(w http.ResponseWriter, r *http.Request) { @@ -282,12 +289,11 @@ func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { } func TestRepositoriesService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repositories/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeLicensesPreview) fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) }) @@ -296,14 +302,14 @@ func TestRepositoriesService_GetByID(t *testing.T) { t.Fatalf("Repositories.GetByID returned error: %v", err) } - want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} + want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.GetByID returned %+v, want %+v", repo, want) } } func TestRepositoriesService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() i := true @@ -325,14 +331,14 @@ func TestRepositoriesService_Edit(t *testing.T) { t.Errorf("Repositories.Edit returned error: %v", err) } - want := &Repository{ID: Int(1)} + want := &Repository{ID: Int64(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.Edit returned %+v, want %+v", repo, want) } } func TestRepositoriesService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -346,17 +352,23 @@ func TestRepositoriesService_Delete(t *testing.T) { } func TestRepositoriesService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.Get(context.Background(), "%", "r") testURLParseError(t, err) } func TestRepositoriesService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.Edit(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_ListContributors(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) { @@ -381,7 +393,7 @@ func TestRepositoriesService_ListContributors(t *testing.T) { } func TestRepositoriesService_ListLanguages(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/languages", func(w http.ResponseWriter, r *http.Request) { @@ -401,11 +413,12 @@ func TestRepositoriesService_ListLanguages(t *testing.T) { } func TestRepositoriesService_ListTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/teams", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) @@ -416,14 +429,14 @@ func TestRepositoriesService_ListTeams(t *testing.T) { t.Errorf("Repositories.ListTeams returned error: %v", err) } - want := []*Team{{ID: Int(1)}} + want := []*Team{{ID: Int64(1)}} if !reflect.DeepEqual(teams, want) { t.Errorf("Repositories.ListTeams returned %+v, want %+v", teams, want) } } func TestRepositoriesService_ListTags(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/tags", func(w http.ResponseWriter, r *http.Request) { @@ -455,12 +468,13 @@ func TestRepositoriesService_ListTags(t *testing.T) { } func TestRepositoriesService_ListBranches(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"name":"master", "commit" : {"sha" : "a57781", "url" : "https://api.github.com/repos/o/r/commits/a57781"}}]`) }) @@ -478,12 +492,13 @@ func TestRepositoriesService_ListBranches(t *testing.T) { } func TestRepositoriesService_GetBranch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true}`) }) @@ -509,7 +524,7 @@ func TestRepositoriesService_GetBranch(t *testing.T) { } func TestRepositoriesService_GetBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) { @@ -517,8 +532,37 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) - fmt.Fprintf(w, `{"required_status_checks":{"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"dismissal_restrictions":{"users":[{"id":3,"login":"u"}],"teams":[{"id":4,"slug":"t"}]},"dismiss_stale_reviews":true},"enforce_admins":{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) + fmt.Fprintf(w, `{ + "required_status_checks":{ + "strict":true, + "contexts":["continuous-integration"] + }, + "required_pull_request_reviews":{ + "dismissal_restrictions":{ + "users":[{ + "id":3, + "login":"u" + }], + "teams":[{ + "id":4, + "slug":"t" + }] + }, + "dismiss_stale_reviews":true, + "require_code_owner_reviews":true, + "required_approving_review_count":1 + }, + "enforce_admins":{ + "url":"/repos/o/r/branches/b/protection/enforce_admins", + "enabled":true + }, + "restrictions":{ + "users":[{"id":1,"login":"u"}], + "teams":[{"id":2,"slug":"t"}] + } + }`) }) protection, _, err := client.Repositories.GetBranchProtection(context.Background(), "o", "r", "b") @@ -535,12 +579,14 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { DismissStaleReviews: true, DismissalRestrictions: DismissalRestrictions{ Users: []*User{ - {Login: String("u"), ID: Int(3)}, + {Login: String("u"), ID: Int64(3)}, }, Teams: []*Team{ - {Slug: String("t"), ID: Int(4)}, + {Slug: String("t"), ID: Int64(4)}, }, }, + RequireCodeOwnerReviews: true, + RequiredApprovingReviewCount: 1, }, EnforceAdmins: &AdminEnforcement{ URL: String("/repos/o/r/branches/b/protection/enforce_admins"), @@ -548,10 +594,10 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { }, Restrictions: &BranchRestrictions{ Users: []*User{ - {Login: String("u"), ID: Int(1)}, + {Login: String("u"), ID: Int64(1)}, }, Teams: []*Team{ - {Slug: String("t"), ID: Int(2)}, + {Slug: String("t"), ID: Int64(2)}, }, }, } @@ -561,7 +607,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { } func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProtectionRequest{ @@ -572,8 +618,8 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { RequiredPullRequestReviews: &PullRequestReviewsEnforcementRequest{ DismissStaleReviews: true, DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ - Users: []string{"uu"}, - Teams: []string{"tt"}, + Users: &[]string{"uu"}, + Teams: &[]string{"tt"}, }, }, Restrictions: &BranchRestrictionsRequest{ @@ -590,8 +636,33 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) - fmt.Fprintf(w, `{"required_status_checks":{"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"dismissal_restrictions":{"users":[{"id":3,"login":"uu"}],"teams":[{"id":4,"slug":"tt"}]},"dismiss_stale_reviews":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`) + + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) + fmt.Fprintf(w, `{ + "required_status_checks":{ + "strict":true, + "contexts":["continuous-integration"] + }, + "required_pull_request_reviews":{ + "dismissal_restrictions":{ + "users":[{ + "id":3, + "login":"uu" + }], + "teams":[{ + "id":4, + "slug":"tt" + }] + }, + "dismiss_stale_reviews":true, + "require_code_owner_reviews":true + }, + "restrictions":{ + "users":[{"id":1,"login":"u"}], + "teams":[{"id":2,"slug":"t"}] + } + }`) }) protection, _, err := client.Repositories.UpdateBranchProtection(context.Background(), "o", "r", "b", input) @@ -608,19 +679,20 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { DismissStaleReviews: true, DismissalRestrictions: DismissalRestrictions{ Users: []*User{ - {Login: String("uu"), ID: Int(3)}, + {Login: String("uu"), ID: Int64(3)}, }, Teams: []*Team{ - {Slug: String("tt"), ID: Int(4)}, + {Slug: String("tt"), ID: Int64(4)}, }, }, + RequireCodeOwnerReviews: true, }, Restrictions: &BranchRestrictions{ Users: []*User{ - {Login: String("u"), ID: Int(1)}, + {Login: String("u"), ID: Int64(1)}, }, Teams: []*Team{ - {Slug: String("t"), ID: Int(2)}, + {Slug: String("t"), ID: Int64(2)}, }, }, } @@ -630,12 +702,13 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { } func TestRepositoriesService_RemoveBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) w.WriteHeader(http.StatusNoContent) }) @@ -646,12 +719,15 @@ func TestRepositoriesService_RemoveBranchProtection(t *testing.T) { } func TestRepositoriesService_ListLanguages_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListLanguages(context.Background(), "%", "%") testURLParseError(t, err) } func TestRepositoriesService_License(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/license", func(w http.ResponseWriter, r *http.Request) { @@ -682,7 +758,7 @@ func TestRepositoriesService_License(t *testing.T) { } func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks", func(w http.ResponseWriter, r *http.Request) { @@ -690,7 +766,8 @@ func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{"strict": true,"contexts": ["x","y","z"]}`) }) @@ -708,8 +785,43 @@ func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) { } } +func TestRepositoriesService_UpdateRequiredStatusChecks(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &RequiredStatusChecksRequest{ + Strict: Bool(true), + Contexts: []string{"continuous-integration"}, + } + + mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks", func(w http.ResponseWriter, r *http.Request) { + v := new(RequiredStatusChecksRequest) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + testHeader(t, r, "Accept", mediaTypeV3) + fmt.Fprintf(w, `{"strict":true,"contexts":["continuous-integration"]}`) + }) + + statusChecks, _, err := client.Repositories.UpdateRequiredStatusChecks(context.Background(), "o", "r", "b", input) + if err != nil { + t.Errorf("Repositories.UpdateRequiredStatusChecks returned error: %v", err) + } + + want := &RequiredStatusChecks{ + Strict: true, + Contexts: []string{"continuous-integration"}, + } + if !reflect.DeepEqual(statusChecks, want) { + t.Errorf("Repositories.UpdateRequiredStatusChecks returned %+v, want %+v", statusChecks, want) + } +} + func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks/contexts", func(w http.ResponseWriter, r *http.Request) { @@ -717,7 +829,8 @@ func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `["x", "y", "z"]`) }) @@ -733,13 +846,22 @@ func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) { } func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) - fmt.Fprintf(w, `{"dismissal_restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]},"dismiss_stale_reviews":true}`) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) + fmt.Fprintf(w, `{ + "dismissal_restrictions":{ + "users":[{"id":1,"login":"u"}], + "teams":[{"id":2,"slug":"t"}] + }, + "dismiss_stale_reviews":true, + "require_code_owner_reviews":true, + "required_approving_review_count":1 + }`) }) enforcement, _, err := client.Repositories.GetPullRequestReviewEnforcement(context.Background(), "o", "r", "b") @@ -751,12 +873,14 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { DismissStaleReviews: true, DismissalRestrictions: DismissalRestrictions{ Users: []*User{ - {Login: String("u"), ID: Int(1)}, + {Login: String("u"), ID: Int64(1)}, }, Teams: []*Team{ - {Slug: String("t"), ID: Int(2)}, + {Slug: String("t"), ID: Int64(2)}, }, }, + RequireCodeOwnerReviews: true, + RequiredApprovingReviewCount: 1, } if !reflect.DeepEqual(enforcement, want) { @@ -765,13 +889,13 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewsEnforcementUpdate{ DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ - Users: []string{"u"}, - Teams: []string{"t"}, + Users: &[]string{"u"}, + Teams: &[]string{"t"}, }, } @@ -783,8 +907,17 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) - fmt.Fprintf(w, `{"dismissal_restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]},"dismiss_stale_reviews":true}`) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) + fmt.Fprintf(w, `{ + "dismissal_restrictions":{ + "users":[{"id":1,"login":"u"}], + "teams":[{"id":2,"slug":"t"}] + }, + "dismiss_stale_reviews":true, + "require_code_owner_reviews":true, + "required_approving_review_count":3 + }`) }) enforcement, _, err := client.Repositories.UpdatePullRequestReviewEnforcement(context.Background(), "o", "r", "b", input) @@ -796,12 +929,14 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { DismissStaleReviews: true, DismissalRestrictions: DismissalRestrictions{ Users: []*User{ - {Login: String("u"), ID: Int(1)}, + {Login: String("u"), ID: Int64(1)}, }, Teams: []*Team{ - {Slug: String("t"), ID: Int(2)}, + {Slug: String("t"), ID: Int64(2)}, }, }, + RequireCodeOwnerReviews: true, + RequiredApprovingReviewCount: 3, } if !reflect.DeepEqual(enforcement, want) { t.Errorf("Repositories.UpdatePullRequestReviewEnforcement returned %+v, want %+v", enforcement, want) @@ -809,14 +944,15 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + // TODO: remove custom Accept header when this API fully launches + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) testBody(t, r, `{"dismissal_restrictions":[]}`+"\n") - fmt.Fprintf(w, `{"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":true}`) + fmt.Fprintf(w, `{"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":1}`) }) enforcement, _, err := client.Repositories.DisableDismissalRestrictions(context.Background(), "o", "r", "b") @@ -830,6 +966,8 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { Users: []*User{}, Teams: []*Team{}, }, + RequireCodeOwnerReviews: true, + RequiredApprovingReviewCount: 1, } if !reflect.DeepEqual(enforcement, want) { t.Errorf("Repositories.DisableDismissalRestrictions returned %+v, want %+v", enforcement, want) @@ -837,12 +975,12 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { } func TestRepositoriesService_RemovePullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) w.WriteHeader(http.StatusNoContent) }) @@ -853,12 +991,12 @@ func TestRepositoriesService_RemovePullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_GetAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true}`) }) @@ -878,12 +1016,12 @@ func TestRepositoriesService_GetAdminEnforcement(t *testing.T) { } func TestRepositoriesService_AddAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true}`) }) @@ -902,12 +1040,12 @@ func TestRepositoriesService_AddAdminEnforcement(t *testing.T) { } func TestRepositoriesService_RemoveAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview) + testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) w.WriteHeader(http.StatusNoContent) }) @@ -917,22 +1055,119 @@ func TestRepositoriesService_RemoveAdminEnforcement(t *testing.T) { } } +func TestRepositoriesService_GetSignaturesProtectedBranch(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/branches/b/protection/required_signatures", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeSignaturePreview) + fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/required_signatures","enabled":false}`) + }) + + signature, _, err := client.Repositories.GetSignaturesProtectedBranch(context.Background(), "o", "r", "b") + if err != nil { + t.Errorf("Repositories.GetSignaturesProtectedBranch returned error: %v", err) + } + + want := &SignaturesProtectedBranch{ + URL: String("/repos/o/r/branches/b/protection/required_signatures"), + Enabled: Bool(false), + } + + if !reflect.DeepEqual(signature, want) { + t.Errorf("Repositories.GetSignaturesProtectedBranch returned %+v, want %+v", signature, want) + } +} + +func TestRepositoriesService_RequireSignaturesOnProtectedBranch(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/branches/b/protection/required_signatures", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeSignaturePreview) + fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/required_signatures","enabled":true}`) + }) + + signature, _, err := client.Repositories.RequireSignaturesOnProtectedBranch(context.Background(), "o", "r", "b") + if err != nil { + t.Errorf("Repositories.RequireSignaturesOnProtectedBranch returned error: %v", err) + } + + want := &SignaturesProtectedBranch{ + URL: String("/repos/o/r/branches/b/protection/required_signatures"), + Enabled: Bool(true), + } + + if !reflect.DeepEqual(signature, want) { + t.Errorf("Repositories.RequireSignaturesOnProtectedBranch returned %+v, want %+v", signature, want) + } +} + +func TestRepositoriesService_OptionalSignaturesOnProtectedBranch(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/branches/b/protection/required_signatures", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeSignaturePreview) + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Repositories.OptionalSignaturesOnProtectedBranch(context.Background(), "o", "r", "b") + if err != nil { + t.Errorf("Repositories.OptionalSignaturesOnProtectedBranch returned error: %v", err) + } +} + func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctions(t *testing.T) { req := PullRequestReviewsEnforcementRequest{} - json, err := json.Marshal(req) + got, err := json.Marshal(req) if err != nil { t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned error: %v", err) } - want := `{"dismissal_restrictions":[],"dismiss_stale_reviews":false}` - if want != string(json) { - t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(json), want) + want := `{"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}` + if want != string(got) { + t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(got), want) + } + + req = PullRequestReviewsEnforcementRequest{ + DismissalRestrictionsRequest: &DismissalRestrictionsRequest{}, + } + + got, err = json.Marshal(req) + if err != nil { + t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned error: %v", err) + } + + want = `{"dismissal_restrictions":{},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}` + if want != string(got) { + t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(got), want) + } + + req = PullRequestReviewsEnforcementRequest{ + DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ + Users: &[]string{}, + Teams: &[]string{}, + }, + } + + got, err = json.Marshal(req) + if err != nil { + t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned error: %v", err) + } + + want = `{"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}` + if want != string(got) { + t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(got), want) } } func TestRepositoriesService_ListAllTopics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -946,14 +1181,35 @@ func TestRepositoriesService_ListAllTopics(t *testing.T) { t.Fatalf("Repositories.ListAllTopics returned error: %v", err) } - want := &Topics{Names: []string{"go", "go-github", "github"}} + want := []string{"go", "go-github", "github"} + if !reflect.DeepEqual(got, want) { + t.Errorf("Repositories.ListAllTopics returned %+v, want %+v", got, want) + } +} + +func TestRepositoriesService_ListAllTopics_emptyTopics(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeTopicsPreview) + fmt.Fprint(w, `{"names":[]}`) + }) + + got, _, err := client.Repositories.ListAllTopics(context.Background(), "o", "r") + if err != nil { + t.Fatalf("Repositories.ListAllTopics returned error: %v", err) + } + + want := []string{} if !reflect.DeepEqual(got, want) { t.Errorf("Repositories.ListAllTopics returned %+v, want %+v", got, want) } } func TestRepositoriesService_ReplaceAllTopics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -962,13 +1218,87 @@ func TestRepositoriesService_ReplaceAllTopics(t *testing.T) { fmt.Fprint(w, `{"names":["go", "go-github", "github"]}`) }) - got, _, err := client.Repositories.ReplaceAllTopics(context.Background(), "o", "r", &Topics{Names: []string{"go", "go-github", "github"}}) + got, _, err := client.Repositories.ReplaceAllTopics(context.Background(), "o", "r", []string{"go", "go-github", "github"}) if err != nil { t.Fatalf("Repositories.ReplaceAllTopics returned error: %v", err) } - want := &Topics{Names: []string{"go", "go-github", "github"}} + want := []string{"go", "go-github", "github"} if !reflect.DeepEqual(got, want) { t.Errorf("Repositories.ReplaceAllTopics returned %+v, want %+v", got, want) } } + +func TestRepositoriesService_ReplaceAllTopics_nilSlice(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Accept", mediaTypeTopicsPreview) + testBody(t, r, `{"names":[]}`+"\n") + fmt.Fprint(w, `{"names":[]}`) + }) + + got, _, err := client.Repositories.ReplaceAllTopics(context.Background(), "o", "r", nil) + if err != nil { + t.Fatalf("Repositories.ReplaceAllTopics returned error: %v", err) + } + + want := []string{} + if !reflect.DeepEqual(got, want) { + t.Errorf("Repositories.ReplaceAllTopics returned %+v, want %+v", got, want) + } +} + +func TestRepositoriesService_ReplaceAllTopics_emptySlice(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Accept", mediaTypeTopicsPreview) + testBody(t, r, `{"names":[]}`+"\n") + fmt.Fprint(w, `{"names":[]}`) + }) + + got, _, err := client.Repositories.ReplaceAllTopics(context.Background(), "o", "r", []string{}) + if err != nil { + t.Fatalf("Repositories.ReplaceAllTopics returned error: %v", err) + } + + want := []string{} + if !reflect.DeepEqual(got, want) { + t.Errorf("Repositories.ReplaceAllTopics returned %+v, want %+v", got, want) + } +} + +func TestRepositoriesService_Transfer(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := TransferRequest{NewOwner: "a", TeamID: []int64{123}} + + mux.HandleFunc("/repos/o/r/transfer", func(w http.ResponseWriter, r *http.Request) { + var v TransferRequest + json.NewDecoder(r.Body).Decode(&v) + + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeRepositoryTransferPreview) + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"owner":{"login":"a"}}`) + }) + + got, _, err := client.Repositories.Transfer(context.Background(), "o", "r", input) + if err != nil { + t.Errorf("Repositories.Transfer returned error: %v", err) + } + + want := &Repository{Owner: &User{Login: String("a")}} + if !reflect.DeepEqual(got, want) { + t.Errorf("Repositories.Transfer returned %+v, want %+v", got, want) + } +} diff --git a/vendor/github.com/google/go-github/github/repos_traffic_test.go b/vendor/github.com/google/go-github/github/repos_traffic_test.go index c425f5cd5..0a2eb4f36 100644 --- a/vendor/github.com/google/go-github/github/repos_traffic_test.go +++ b/vendor/github.com/google/go-github/github/repos_traffic_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/popular/referrers", func(w http.ResponseWriter, r *http.Request) { @@ -43,7 +43,7 @@ func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { } func TestRepositoriesService_ListTrafficPaths(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/popular/paths", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +73,7 @@ func TestRepositoriesService_ListTrafficPaths(t *testing.T) { } func TestRepositoriesService_ListTrafficViews(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/views", func(w http.ResponseWriter, r *http.Request) { @@ -109,7 +109,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { } func TestRepositoriesService_ListTrafficClones(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/clones", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/search.go b/vendor/github.com/google/go-github/github/search.go index a59735202..abaf5e1f0 100644 --- a/vendor/github.com/google/go-github/github/search.go +++ b/vendor/github.com/google/go-github/github/search.go @@ -8,6 +8,9 @@ package github import ( "context" "fmt" + "net/url" + "strconv" + "strings" qs "github.com/google/go-querystring/query" ) @@ -48,6 +51,12 @@ type SearchOptions struct { ListOptions } +// Common search parameters. +type searchParameters struct { + Query string + RepositoryID *int64 // Sent if non-nil. +} + // RepositoriesSearchResult represents the result of a repositories search. type RepositoriesSearchResult struct { Total *int `json:"total_count,omitempty"` @@ -60,7 +69,7 @@ type RepositoriesSearchResult struct { // GitHub API docs: https://developer.github.com/v3/search/#search-repositories func (s *SearchService) Repositories(ctx context.Context, query string, opt *SearchOptions) (*RepositoriesSearchResult, *Response, error) { result := new(RepositoriesSearchResult) - resp, err := s.search(ctx, "repositories", query, opt, result) + resp, err := s.search(ctx, "repositories", &searchParameters{Query: query}, opt, result) return result, resp, err } @@ -91,7 +100,7 @@ type CommitResult struct { // GitHub API docs: https://developer.github.com/v3/search/#search-commits func (s *SearchService) Commits(ctx context.Context, query string, opt *SearchOptions) (*CommitsSearchResult, *Response, error) { result := new(CommitsSearchResult) - resp, err := s.search(ctx, "commits", query, opt, result) + resp, err := s.search(ctx, "commits", &searchParameters{Query: query}, opt, result) return result, resp, err } @@ -107,7 +116,7 @@ type IssuesSearchResult struct { // GitHub API docs: https://developer.github.com/v3/search/#search-issues func (s *SearchService) Issues(ctx context.Context, query string, opt *SearchOptions) (*IssuesSearchResult, *Response, error) { result := new(IssuesSearchResult) - resp, err := s.search(ctx, "issues", query, opt, result) + resp, err := s.search(ctx, "issues", &searchParameters{Query: query}, opt, result) return result, resp, err } @@ -123,7 +132,7 @@ type UsersSearchResult struct { // GitHub API docs: https://developer.github.com/v3/search/#search-users func (s *SearchService) Users(ctx context.Context, query string, opt *SearchOptions) (*UsersSearchResult, *Response, error) { result := new(UsersSearchResult) - resp, err := s.search(ctx, "users", query, opt, result) + resp, err := s.search(ctx, "users", &searchParameters{Query: query}, opt, result) return result, resp, err } @@ -172,19 +181,57 @@ func (c CodeResult) String() string { // GitHub API docs: https://developer.github.com/v3/search/#search-code func (s *SearchService) Code(ctx context.Context, query string, opt *SearchOptions) (*CodeSearchResult, *Response, error) { result := new(CodeSearchResult) - resp, err := s.search(ctx, "code", query, opt, result) + resp, err := s.search(ctx, "code", &searchParameters{Query: query}, opt, result) + return result, resp, err +} + +// LabelsSearchResult represents the result of a code search. +type LabelsSearchResult struct { + Total *int `json:"total_count,omitempty"` + IncompleteResults *bool `json:"incomplete_results,omitempty"` + Labels []*LabelResult `json:"items,omitempty"` +} + +// LabelResult represents a single search result. +type LabelResult struct { + ID *int64 `json:"id,omitempty"` + URL *string `json:"url,omitempty"` + Name *string `json:"name,omitempty"` + Color *string `json:"color,omitempty"` + Default *bool `json:"default,omitempty"` + Description *string `json:"description,omitempty"` + Score *float64 `json:"score,omitempty"` +} + +func (l LabelResult) String() string { + return Stringify(l) +} + +// Labels searches labels in the repository with ID repoID via various criteria. +// +// GitHub API docs: https://developer.github.com/v3/search/#search-labels +func (s *SearchService) Labels(ctx context.Context, repoID int64, query string, opt *SearchOptions) (*LabelsSearchResult, *Response, error) { + result := new(LabelsSearchResult) + resp, err := s.search(ctx, "labels", &searchParameters{RepositoryID: &repoID, Query: query}, opt, result) return result, resp, err } // Helper function that executes search queries against different -// GitHub search types (repositories, commits, code, issues, users) -func (s *SearchService) search(ctx context.Context, searchType string, query string, opt *SearchOptions, result interface{}) (*Response, error) { +// GitHub search types (repositories, commits, code, issues, users, labels) +func (s *SearchService) search(ctx context.Context, searchType string, parameters *searchParameters, opt *SearchOptions, result interface{}) (*Response, error) { params, err := qs.Values(opt) if err != nil { return nil, err } - params.Set("q", query) - u := fmt.Sprintf("search/%s?%s", searchType, params.Encode()) + q := strings.Replace(parameters.Query, " ", "+", -1) + if parameters.RepositoryID != nil { + params.Set("repository_id", strconv.FormatInt(*parameters.RepositoryID, 10)) + } + query := "q=" + url.PathEscape(q) + if v := params.Encode(); v != "" { + query = query + "&" + v + } + u := fmt.Sprintf("search/%s?%s", searchType, query) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -200,6 +247,10 @@ func (s *SearchService) search(ctx context.Context, searchType string, query str // Accept header for search repositories based on topics preview endpoint // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) + case searchType == "labels": + // Accept header for search labels based on label description preview endpoint. + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeLabelDescriptionSearchPreview) case opt != nil && opt.TextMatch: // Accept header defaults to "application/vnd.github.v3+json" // We change it here to fetch back text-match metadata diff --git a/vendor/github.com/google/go-github/github/search_test.go b/vendor/github.com/google/go-github/github/search_test.go index 1276e01d8..f6e40d213 100644 --- a/vendor/github.com/google/go-github/github/search_test.go +++ b/vendor/github.com/google/go-github/github/search_test.go @@ -15,7 +15,7 @@ import ( ) func TestSearchService_Repositories(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestSearchService_Repositories(t *testing.T) { want := &RepositoriesSearchResult{ Total: Int(4), IncompleteResults: Bool(false), - Repositories: []Repository{{ID: Int(1)}, {ID: Int(2)}}, + Repositories: []Repository{{ID: Int64(1)}, {ID: Int64(2)}}, } if !reflect.DeepEqual(result, want) { t.Errorf("Search.Repositories returned %+v, want %+v", result, want) @@ -48,7 +48,7 @@ func TestSearchService_Repositories(t *testing.T) { } func TestSearchService_Commits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/commits", func(w http.ResponseWriter, r *http.Request) { @@ -79,7 +79,7 @@ func TestSearchService_Commits(t *testing.T) { } func TestSearchService_Issues(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/issues", func(w http.ResponseWriter, r *http.Request) { @@ -111,25 +111,71 @@ func TestSearchService_Issues(t *testing.T) { } } -func TestSearchService_Issues_withQualifiers(t *testing.T) { - setup() +func TestSearchService_Issues_withQualifiersNoOpts(t *testing.T) { + client, mux, _, teardown := setup() defer teardown() + const q = "gopher is:issue label:bug language:go pushed:>=2018-01-01 stars:>=200" + + var requestURI string mux.HandleFunc("/search/issues", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "q": "gopher is:issue label:bug language:go", + "q": q, }) + requestURI = r.RequestURI fmt.Fprint(w, `{"total_count": 4, "incomplete_results": true, "items": [{"number":1},{"number":2}]}`) }) opts := &SearchOptions{} - result, _, err := client.Search.Issues(context.Background(), "gopher is:issue label:bug language:go", opts) + result, _, err := client.Search.Issues(context.Background(), q, opts) if err != nil { t.Errorf("Search.Issues returned error: %v", err) } + if want := "/api-v3/search/issues?q=gopher+is:issue+label:bug+language:go+pushed:%3E=2018-01-01+stars:%3E=200"; requestURI != want { + t.Fatalf("URI encoding failed: got %v, want %v", requestURI, want) + } + + want := &IssuesSearchResult{ + Total: Int(4), + IncompleteResults: Bool(true), + Issues: []Issue{{Number: Int(1)}, {Number: Int(2)}}, + } + if !reflect.DeepEqual(result, want) { + t.Errorf("Search.Issues returned %+v, want %+v", result, want) + } +} + +func TestSearchService_Issues_withQualifiersAndOpts(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + const q = "gopher is:issue label:bug language:go pushed:>=2018-01-01 stars:>=200" + + var requestURI string + mux.HandleFunc("/search/issues", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "q": q, + "sort": "forks", + }) + requestURI = r.RequestURI + + fmt.Fprint(w, `{"total_count": 4, "incomplete_results": true, "items": [{"number":1},{"number":2}]}`) + }) + + opts := &SearchOptions{Sort: "forks"} + result, _, err := client.Search.Issues(context.Background(), q, opts) + if err != nil { + t.Errorf("Search.Issues returned error: %v", err) + } + + if want := "/api-v3/search/issues?q=gopher+is:issue+label:bug+language:go+pushed:%3E=2018-01-01+stars:%3E=200&sort=forks"; requestURI != want { + t.Fatalf("URI encoding failed: got %v, want %v", requestURI, want) + } + want := &IssuesSearchResult{ Total: Int(4), IncompleteResults: Bool(true), @@ -141,7 +187,7 @@ func TestSearchService_Issues_withQualifiers(t *testing.T) { } func TestSearchService_Users(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/users", func(w http.ResponseWriter, r *http.Request) { @@ -166,7 +212,7 @@ func TestSearchService_Users(t *testing.T) { want := &UsersSearchResult{ Total: Int(4), IncompleteResults: Bool(false), - Users: []User{{ID: Int(1)}, {ID: Int(2)}}, + Users: []User{{ID: Int64(1)}, {ID: Int64(2)}}, } if !reflect.DeepEqual(result, want) { t.Errorf("Search.Users returned %+v, want %+v", result, want) @@ -174,7 +220,7 @@ func TestSearchService_Users(t *testing.T) { } func TestSearchService_Code(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) { @@ -207,7 +253,7 @@ func TestSearchService_Code(t *testing.T) { } func TestSearchService_CodeTextMatch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) { @@ -266,3 +312,40 @@ func TestSearchService_CodeTextMatch(t *testing.T) { t.Errorf("Search.Code returned %+v, want %+v", result, want) } } + +func TestSearchService_Labels(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/search/labels", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "repository_id": "1234", + "q": "blah", + "sort": "updated", + "order": "desc", + "page": "2", + "per_page": "2", + }) + + fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"id": 1234, "name":"bug", "description": "some text"},{"id": 4567, "name":"feature"}]}`) + }) + + opts := &SearchOptions{Sort: "updated", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}} + result, _, err := client.Search.Labels(context.Background(), 1234, "blah", opts) + if err != nil { + t.Errorf("Search.Code returned error: %v", err) + } + + want := &LabelsSearchResult{ + Total: Int(4), + IncompleteResults: Bool(false), + Labels: []*LabelResult{ + {ID: Int64(1234), Name: String("bug"), Description: String("some text")}, + {ID: Int64(4567), Name: String("feature")}, + }, + } + if !reflect.DeepEqual(result, want) { + t.Errorf("Search.Labels returned %+v, want %+v", result, want) + } +} diff --git a/vendor/github.com/google/go-github/github/strings_test.go b/vendor/github.com/google/go-github/github/strings_test.go index 6af88acd3..e16d4a547 100644 --- a/vendor/github.com/google/go-github/github/strings_test.go +++ b/vendor/github.com/google/go-github/github/strings_test.go @@ -54,19 +54,19 @@ func TestStringify(t *testing.T) { // actual GitHub structs { - Timestamp{time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)}, + Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)}, `github.Timestamp{2006-01-02 15:04:05 +0000 UTC}`, }, { - &Timestamp{time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)}, + &Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)}, `github.Timestamp{2006-01-02 15:04:05 +0000 UTC}`, }, { - User{ID: Int(123), Name: String("n")}, + User{ID: Int64(123), Name: String("n")}, `github.User{ID:123, Name:"n"}`, }, { - Repository{Owner: &User{ID: Int(123)}}, + Repository{Owner: &User{ID: Int64(123)}}, `github.Repository{Owner:github.User{ID:123}}`, }, } @@ -96,37 +96,37 @@ func TestString(t *testing.T) { {CommitsComparison{TotalCommits: Int(1)}, `github.CommitsComparison{TotalCommits:1}`}, {Commit{SHA: String("s")}, `github.Commit{SHA:"s"}`}, {Event{ID: String("1")}, `github.Event{ID:"1"}`}, - {GistComment{ID: Int(1)}, `github.GistComment{ID:1}`}, + {GistComment{ID: Int64(1)}, `github.GistComment{ID:1}`}, {GistFile{Size: Int(1)}, `github.GistFile{Size:1}`}, {Gist{ID: String("1")}, `github.Gist{ID:"1", Files:map[]}`}, {GitObject{SHA: String("s")}, `github.GitObject{SHA:"s"}`}, {Gitignore{Name: String("n")}, `github.Gitignore{Name:"n"}`}, - {Hook{ID: Int(1)}, `github.Hook{Config:map[], ID:1}`}, - {IssueComment{ID: Int(1)}, `github.IssueComment{ID:1}`}, + {Hook{ID: Int64(1)}, `github.Hook{ID:1, Config:map[]}`}, + {IssueComment{ID: Int64(1)}, `github.IssueComment{ID:1}`}, {Issue{Number: Int(1)}, `github.Issue{Number:1}`}, - {Key{ID: Int(1)}, `github.Key{ID:1}`}, - {Label{ID: Int(1), Name: String("l")}, `github.Label{ID:1, Name:"l"}`}, - {Organization{ID: Int(1)}, `github.Organization{ID:1}`}, - {PullRequestComment{ID: Int(1)}, `github.PullRequestComment{ID:1}`}, + {Key{ID: Int64(1)}, `github.Key{ID:1}`}, + {Label{ID: Int64(1), Name: String("l")}, `github.Label{ID:1, Name:"l"}`}, + {Organization{ID: Int64(1)}, `github.Organization{ID:1}`}, + {PullRequestComment{ID: Int64(1)}, `github.PullRequestComment{ID:1}`}, {PullRequest{Number: Int(1)}, `github.PullRequest{Number:1}`}, - {PullRequestReview{ID: Int(1)}, `github.PullRequestReview{ID:1}`}, + {PullRequestReview{ID: Int64(1)}, `github.PullRequestReview{ID:1}`}, {DraftReviewComment{Position: Int(1)}, `github.DraftReviewComment{Position:1}`}, {PullRequestReviewRequest{Body: String("r")}, `github.PullRequestReviewRequest{Body:"r"}`}, {PullRequestReviewDismissalRequest{Message: String("r")}, `github.PullRequestReviewDismissalRequest{Message:"r"}`}, {PushEventCommit{SHA: String("s")}, `github.PushEventCommit{SHA:"s"}`}, - {PushEvent{PushID: Int(1)}, `github.PushEvent{PushID:1}`}, + {PushEvent{PushID: Int64(1)}, `github.PushEvent{PushID:1}`}, {Reference{Ref: String("r")}, `github.Reference{Ref:"r"}`}, - {ReleaseAsset{ID: Int(1)}, `github.ReleaseAsset{ID:1}`}, - {RepoStatus{ID: Int(1)}, `github.RepoStatus{ID:1}`}, - {RepositoryComment{ID: Int(1)}, `github.RepositoryComment{ID:1}`}, + {ReleaseAsset{ID: Int64(1)}, `github.ReleaseAsset{ID:1}`}, + {RepoStatus{ID: Int64(1)}, `github.RepoStatus{ID:1}`}, + {RepositoryComment{ID: Int64(1)}, `github.RepositoryComment{ID:1}`}, {RepositoryCommit{SHA: String("s")}, `github.RepositoryCommit{SHA:"s"}`}, {RepositoryContent{Name: String("n")}, `github.RepositoryContent{Name:"n"}`}, - {RepositoryRelease{ID: Int(1)}, `github.RepositoryRelease{ID:1}`}, - {Repository{ID: Int(1)}, `github.Repository{ID:1}`}, - {Team{ID: Int(1)}, `github.Team{ID:1}`}, + {RepositoryRelease{ID: Int64(1)}, `github.RepositoryRelease{ID:1}`}, + {Repository{ID: Int64(1)}, `github.Repository{ID:1}`}, + {Team{ID: Int64(1)}, `github.Team{ID:1}`}, {TreeEntry{SHA: String("s")}, `github.TreeEntry{SHA:"s"}`}, {Tree{SHA: String("s")}, `github.Tree{SHA:"s"}`}, - {User{ID: Int(1)}, `github.User{ID:1}`}, + {User{ID: Int64(1)}, `github.User{ID:1}`}, {WebHookAuthor{Name: String("n")}, `github.WebHookAuthor{Name:"n"}`}, {WebHookCommit{ID: String("1")}, `github.WebHookCommit{ID:"1"}`}, {WebHookPayload{Ref: String("r")}, `github.WebHookPayload{Ref:"r"}`}, diff --git a/vendor/github.com/google/go-github/github/teams.go b/vendor/github.com/google/go-github/github/teams.go new file mode 100644 index 000000000..c3773e00e --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams.go @@ -0,0 +1,357 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "strings" + "time" +) + +// TeamsService provides access to the team-related functions +// in the GitHub API. +// +// GitHub API docs: https://developer.github.com/v3/teams/ +type TeamsService service + +// Team represents a team within a GitHub organization. Teams are used to +// manage access to an organization's repositories. +type Team struct { + ID *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + URL *string `json:"url,omitempty"` + Slug *string `json:"slug,omitempty"` + + // Permission specifies the default permission for repositories owned by the team. + Permission *string `json:"permission,omitempty"` + + // Privacy identifies the level of privacy this team should have. + // Possible values are: + // secret - only visible to organization owners and members of this team + // closed - visible to all members of this organization + // Default is "secret". + Privacy *string `json:"privacy,omitempty"` + + MembersCount *int `json:"members_count,omitempty"` + ReposCount *int `json:"repos_count,omitempty"` + Organization *Organization `json:"organization,omitempty"` + MembersURL *string `json:"members_url,omitempty"` + RepositoriesURL *string `json:"repositories_url,omitempty"` + Parent *Team `json:"parent,omitempty"` + + // LDAPDN is only available in GitHub Enterprise and when the team + // membership is synchronized with LDAP. + LDAPDN *string `json:"ldap_dn,omitempty"` +} + +func (t Team) String() string { + return Stringify(t) +} + +// Invitation represents a team member's invitation status. +type Invitation struct { + ID *int64 `json:"id,omitempty"` + Login *string `json:"login,omitempty"` + Email *string `json:"email,omitempty"` + // Role can be one of the values - 'direct_member', 'admin', 'billing_manager', 'hiring_manager', or 'reinstate'. + Role *string `json:"role,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + Inviter *User `json:"inviter,omitempty"` + TeamCount *int `json:"team_count,omitempty"` + InvitationTeamURL *string `json:"invitation_team_url,omitempty"` +} + +func (i Invitation) String() string { + return Stringify(i) +} + +// ListTeams lists all of the teams for an organization. +// +// GitHub API docs: https://developer.github.com/v3/teams/#list-teams +func (s *TeamsService) ListTeams(ctx context.Context, org string, opt *ListOptions) ([]*Team, *Response, error) { + u := fmt.Sprintf("orgs/%v/teams", org) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + var teams []*Team + resp, err := s.client.Do(ctx, req, &teams) + if err != nil { + return nil, resp, err + } + + return teams, resp, nil +} + +// GetTeam fetches a team by ID. +// +// GitHub API docs: https://developer.github.com/v3/teams/#get-team +func (s *TeamsService) GetTeam(ctx context.Context, team int64) (*Team, *Response, error) { + u := fmt.Sprintf("teams/%v", team) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + t := new(Team) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// NewTeam represents a team to be created or modified. +type NewTeam struct { + Name string `json:"name"` // Name of the team. (Required.) + Description *string `json:"description,omitempty"` + Maintainers []string `json:"maintainers,omitempty"` + RepoNames []string `json:"repo_names,omitempty"` + ParentTeamID *int64 `json:"parent_team_id,omitempty"` + + // Deprecated: Permission is deprecated when creating or editing a team in an org + // using the new GitHub permission model. It no longer identifies the + // permission a team has on its repos, but only specifies the default + // permission a repo is initially added with. Avoid confusion by + // specifying a permission value when calling AddTeamRepo. + Permission *string `json:"permission,omitempty"` + + // Privacy identifies the level of privacy this team should have. + // Possible values are: + // secret - only visible to organization owners and members of this team + // closed - visible to all members of this organization + // Default is "secret". + Privacy *string `json:"privacy,omitempty"` + + // LDAPDN may be used in GitHub Enterprise when the team membership + // is synchronized with LDAP. + LDAPDN *string `json:"ldap_dn,omitempty"` +} + +func (s NewTeam) String() string { + return Stringify(s) +} + +// CreateTeam creates a new team within an organization. +// +// GitHub API docs: https://developer.github.com/v3/teams/#create-team +func (s *TeamsService) CreateTeam(ctx context.Context, org string, team NewTeam) (*Team, *Response, error) { + u := fmt.Sprintf("orgs/%v/teams", org) + req, err := s.client.NewRequest("POST", u, team) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + t := new(Team) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// EditTeam edits a team. +// +// GitHub API docs: https://developer.github.com/v3/teams/#edit-team +func (s *TeamsService) EditTeam(ctx context.Context, id int64, team NewTeam) (*Team, *Response, error) { + u := fmt.Sprintf("teams/%v", id) + req, err := s.client.NewRequest("PATCH", u, team) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + t := new(Team) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// DeleteTeam deletes a team. +// +// GitHub API docs: https://developer.github.com/v3/teams/#delete-team +func (s *TeamsService) DeleteTeam(ctx context.Context, team int64) (*Response, error) { + u := fmt.Sprintf("teams/%v", team) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + return s.client.Do(ctx, req, nil) +} + +// ListChildTeams lists child teams for a team. +// +// GitHub API docs: https://developer.github.com/v3/teams/#list-child-teams +func (s *TeamsService) ListChildTeams(ctx context.Context, teamID int64, opt *ListOptions) ([]*Team, *Response, error) { + u := fmt.Sprintf("teams/%v/teams", teamID) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + var teams []*Team + resp, err := s.client.Do(ctx, req, &teams) + if err != nil { + return nil, resp, err + } + + return teams, resp, nil +} + +// ListTeamRepos lists the repositories that the specified team has access to. +// +// GitHub API docs: https://developer.github.com/v3/teams/#list-team-repos +func (s *TeamsService) ListTeamRepos(ctx context.Context, team int64, opt *ListOptions) ([]*Repository, *Response, error) { + u := fmt.Sprintf("teams/%v/repos", team) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when topics API fully launches. + headers := []string{mediaTypeTopicsPreview, mediaTypeNestedTeamsPreview} + req.Header.Set("Accept", strings.Join(headers, ", ")) + + var repos []*Repository + resp, err := s.client.Do(ctx, req, &repos) + if err != nil { + return nil, resp, err + } + + return repos, resp, nil +} + +// IsTeamRepo checks if a team manages the specified repository. If the +// repository is managed by team, a Repository is returned which includes the +// permissions team has for that repo. +// +// GitHub API docs: https://developer.github.com/v3/teams/#check-if-a-team-manages-a-repository +func (s *TeamsService) IsTeamRepo(ctx context.Context, team int64, owner string, repo string) (*Repository, *Response, error) { + u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + headers := []string{mediaTypeOrgPermissionRepo, mediaTypeNestedTeamsPreview} + req.Header.Set("Accept", strings.Join(headers, ", ")) + + repository := new(Repository) + resp, err := s.client.Do(ctx, req, repository) + if err != nil { + return nil, resp, err + } + + return repository, resp, nil +} + +// TeamAddTeamRepoOptions specifies the optional parameters to the +// TeamsService.AddTeamRepo method. +type TeamAddTeamRepoOptions struct { + // Permission specifies the permission to grant the team on this repository. + // Possible values are: + // pull - team members can pull, but not push to or administer this repository + // push - team members can pull and push, but not administer this repository + // admin - team members can pull, push and administer this repository + // + // If not specified, the team's permission attribute will be used. + Permission string `json:"permission,omitempty"` +} + +// AddTeamRepo adds a repository to be managed by the specified team. The +// specified repository must be owned by the organization to which the team +// belongs, or a direct fork of a repository owned by the organization. +// +// GitHub API docs: https://developer.github.com/v3/teams/#add-team-repo +func (s *TeamsService) AddTeamRepo(ctx context.Context, team int64, owner string, repo string, opt *TeamAddTeamRepoOptions) (*Response, error) { + u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) + req, err := s.client.NewRequest("PUT", u, opt) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// RemoveTeamRepo removes a repository from being managed by the specified +// team. Note that this does not delete the repository, it just removes it +// from the team. +// +// GitHub API docs: https://developer.github.com/v3/teams/#remove-team-repo +func (s *TeamsService) RemoveTeamRepo(ctx context.Context, team int64, owner string, repo string) (*Response, error) { + u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// ListUserTeams lists a user's teams +// GitHub API docs: https://developer.github.com/v3/teams/#list-user-teams +func (s *TeamsService) ListUserTeams(ctx context.Context, opt *ListOptions) ([]*Team, *Response, error) { + u := "user/teams" + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + var teams []*Team + resp, err := s.client.Do(ctx, req, &teams) + if err != nil { + return nil, resp, err + } + + return teams, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/teams_discussion_comments.go b/vendor/github.com/google/go-github/github/teams_discussion_comments.go new file mode 100644 index 000000000..a0206b9c9 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_discussion_comments.go @@ -0,0 +1,155 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// DiscussionComment represents a GitHub dicussion in a team. +type DiscussionComment struct { + Author *User `json:"author,omitempty"` + Body *string `json:"body,omitempty"` + BodyHTML *string `json:"body_html,omitempty"` + BodyVersion *string `json:"body_version,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + LastEditedAt *Timestamp `json:"last_edited_at,omitempty"` + DiscussionURL *string `json:"discussion_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Number *int `json:"number,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + URL *string `json:"url,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` +} + +func (c DiscussionComment) String() string { + return Stringify(c) +} + +// DiscussionCommentListOptions specifies optional parameters to the +// TeamServices.ListComments method. +type DiscussionCommentListOptions struct { + // Sorts the discussion comments by the date they were created. + // Accepted values are asc and desc. Default is desc. + Direction string `url:"direction,omitempty"` +} + +// ListComments lists all comments on a team discussion. +// Authenticated user must grant read:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#list-comments +func (s *TeamsService) ListComments(ctx context.Context, teamID int64, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments", teamID, discussionNumber) + u, err := addOptions(u, options) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + var comments []*DiscussionComment + resp, err := s.client.Do(ctx, req, &comments) + if err != nil { + return nil, resp, err + } + + return comments, resp, nil +} + +// GetComment gets a specific comment on a team discussion. +// Authenticated user must grant read:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#get-a-single-comment +func (s *TeamsService) GetComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + discussionComment := &DiscussionComment{} + resp, err := s.client.Do(ctx, req, discussionComment) + if err != nil { + return nil, resp, err + } + + return discussionComment, resp, nil +} + +// CreateComment creates a new discussion post on a team discussion. +// Authenticated user must grant write:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#create-a-comment +func (s *TeamsService) CreateComment(ctx context.Context, teamID int64, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments", teamID, discsusionNumber) + req, err := s.client.NewRequest("POST", u, comment) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + discussionComment := &DiscussionComment{} + resp, err := s.client.Do(ctx, req, discussionComment) + if err != nil { + return nil, resp, err + } + + return discussionComment, resp, nil +} + +// EditComment edits the body text of a discussion comment. +// Authenticated user must grant write:discussion scope. +// User is allowed to edit body of a comment only. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#edit-a-comment +func (s *TeamsService) EditComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber) + req, err := s.client.NewRequest("PATCH", u, comment) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + discussionComment := &DiscussionComment{} + resp, err := s.client.Do(ctx, req, discussionComment) + if err != nil { + return nil, resp, err + } + + return discussionComment, resp, nil +} + +// DeleteComment deletes a comment on a team discussion. +// Authenticated user must grant write:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#delete-a-comment +func (s *TeamsService) DeleteComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int) (*Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/teams_discussion_comments_test.go b/vendor/github.com/google/go-github/github/teams_discussion_comments_test.go new file mode 100644 index 000000000..f4c9f96f4 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_discussion_comments_test.go @@ -0,0 +1,203 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" + "time" +) + +func TestTeamsService_ListComments(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions/3/comments", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + testFormValues(t, r, values{ + "direction": "desc", + }) + fmt.Fprintf(w, + `[ + { + "author": { + "login": "author", + "id": 0, + "avatar_url": "https://avatars1.githubusercontent.com/u/0?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/author", + "html_url": "https://github.com/author", + "followers_url": "https://api.github.com/users/author/followers", + "following_url": "https://api.github.com/users/author/following{/other_user}", + "gists_url": "https://api.github.com/users/author/gists{/gist_id}", + "starred_url": "https://api.github.com/users/author/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/author/subscriptions", + "organizations_url": "https://api.github.com/users/author/orgs", + "repos_url": "https://api.github.com/users/author/repos", + "events_url": "https://api.github.com/users/author/events{/privacy}", + "received_events_url": "https://api.github.com/users/author/received_events", + "type": "User", + "site_admin": false + }, + "body": "comment", + "body_html": "

comment

", + "body_version": "version", + "created_at": "2018-01-01T00:00:00Z", + "last_edited_at": null, + "discussion_url": "https://api.github.com/teams/2/discussions/3", + "html_url": "https://github.com/orgs/1/teams/2/discussions/3/comments/4", + "node_id": "node", + "number": 4, + "updated_at": "2018-01-01T00:00:00Z", + "url": "https://api.github.com/teams/2/discussions/3/comments/4" + } + ]`) + }) + + comments, _, err := client.Teams.ListComments(context.Background(), 2, 3, &DiscussionCommentListOptions{"desc"}) + if err != nil { + t.Errorf("Teams.ListComments returned error: %v", err) + } + + want := []*DiscussionComment{ + { + Author: &User{ + Login: String("author"), + ID: Int64(0), + AvatarURL: String("https://avatars1.githubusercontent.com/u/0?v=4"), + GravatarID: String(""), + URL: String("https://api.github.com/users/author"), + HTMLURL: String("https://github.com/author"), + FollowersURL: String("https://api.github.com/users/author/followers"), + FollowingURL: String("https://api.github.com/users/author/following{/other_user}"), + GistsURL: String("https://api.github.com/users/author/gists{/gist_id}"), + StarredURL: String("https://api.github.com/users/author/starred{/owner}{/repo}"), + SubscriptionsURL: String("https://api.github.com/users/author/subscriptions"), + OrganizationsURL: String("https://api.github.com/users/author/orgs"), + ReposURL: String("https://api.github.com/users/author/repos"), + EventsURL: String("https://api.github.com/users/author/events{/privacy}"), + ReceivedEventsURL: String("https://api.github.com/users/author/received_events"), + Type: String("User"), + SiteAdmin: Bool(false), + }, + Body: String("comment"), + BodyHTML: String("

comment

"), + BodyVersion: String("version"), + CreatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + LastEditedAt: nil, + DiscussionURL: String("https://api.github.com/teams/2/discussions/3"), + HTMLURL: String("https://github.com/orgs/1/teams/2/discussions/3/comments/4"), + NodeID: String("node"), + Number: Int(4), + UpdatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + URL: String("https://api.github.com/teams/2/discussions/3/comments/4"), + }, + } + if !reflect.DeepEqual(comments, want) { + t.Errorf("Teams.ListComments returned %+v, want %+v", comments, want) + } +} + +func TestTeamsService_GetComment(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions/3/comments/4", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + fmt.Fprint(w, `{"number":4}`) + }) + + comment, _, err := client.Teams.GetComment(context.Background(), 2, 3, 4) + if err != nil { + t.Errorf("Teams.GetComment returned error: %v", err) + } + + want := &DiscussionComment{Number: Int(4)} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Teams.GetComment returned %+v, want %+v", comment, want) + } +} + +func TestTeamsService_CreateComment(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := DiscussionComment{Body: String("c")} + + mux.HandleFunc("/teams/2/discussions/3/comments", func(w http.ResponseWriter, r *http.Request) { + v := new(DiscussionComment) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"number":4}`) + }) + + comment, _, err := client.Teams.CreateComment(context.Background(), 2, 3, input) + if err != nil { + t.Errorf("Teams.CreateComment returned error: %v", err) + } + + want := &DiscussionComment{Number: Int(4)} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Teams.CreateComment returned %+v, want %+v", comment, want) + } +} + +func TestTeamsService_EditComment(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := DiscussionComment{Body: String("e")} + + mux.HandleFunc("/teams/2/discussions/3/comments/4", func(w http.ResponseWriter, r *http.Request) { + v := new(DiscussionComment) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"number":4}`) + }) + + comment, _, err := client.Teams.EditComment(context.Background(), 2, 3, 4, input) + if err != nil { + t.Errorf("Teams.EditComment returned error: %v", err) + } + + want := &DiscussionComment{Number: Int(4)} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Teams.EditComment returned %+v, want %+v", comment, want) + } +} + +func TestTeamsService_DeleteComment(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions/3/comments/4", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + }) + + _, err := client.Teams.DeleteComment(context.Background(), 2, 3, 4) + if err != nil { + t.Errorf("Teams.DeleteComment returned error: %v", err) + } +} diff --git a/vendor/github.com/google/go-github/github/teams_discussions.go b/vendor/github.com/google/go-github/github/teams_discussions.go new file mode 100644 index 000000000..f491c9d1d --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_discussions.go @@ -0,0 +1,160 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// TeamDiscussion represents a GitHub dicussion in a team. +type TeamDiscussion struct { + Author *User `json:"author,omitempty"` + Body *string `json:"body,omitempty"` + BodyHTML *string `json:"body_html,omitempty"` + BodyVersion *string `json:"body_version,omitempty"` + CommentsCount *int `json:"comments_count,omitempty"` + CommentsURL *string `json:"comments_url,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + LastEditedAt *Timestamp `json:"last_edited_at,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Number *int `json:"number,omitempty"` + Pinned *bool `json:"pinned,omitempty"` + Private *bool `json:"private,omitempty"` + TeamURL *string `json:"team_url,omitempty"` + Title *string `json:"title,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + URL *string `json:"url,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` +} + +func (d TeamDiscussion) String() string { + return Stringify(d) +} + +// DiscussionListOptions specifies optional parameters to the +// TeamServices.ListDiscussions method. +type DiscussionListOptions struct { + // Sorts the discussion by the date they were created. + // Accepted values are asc and desc. Default is desc. + Direction string `url:"direction,omitempty"` +} + +// ListDiscussions lists all discussions on team's page. +// Authenticated user must grant read:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussions/#list-discussions +func (s *TeamsService) ListDiscussions(ctx context.Context, teamID int64, options *DiscussionListOptions) ([]*TeamDiscussion, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions", teamID) + u, err := addOptions(u, options) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + var teamDiscussions []*TeamDiscussion + resp, err := s.client.Do(ctx, req, &teamDiscussions) + if err != nil { + return nil, resp, err + } + + return teamDiscussions, resp, nil +} + +// GetDiscussion gets a specific discussion on a team's page. +// Authenticated user must grant read:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussions/#get-a-single-discussion +func (s *TeamsService) GetDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*TeamDiscussion, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + teamDiscussion := &TeamDiscussion{} + resp, err := s.client.Do(ctx, req, teamDiscussion) + if err != nil { + return nil, resp, err + } + + return teamDiscussion, resp, nil +} + +// CreateDiscussion creates a new discussion post on a team's page. +// Authenticated user must grant write:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussions/#create-a-discussion +func (s *TeamsService) CreateDiscussion(ctx context.Context, teamID int64, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions", teamID) + req, err := s.client.NewRequest("POST", u, discussion) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + teamDiscussion := &TeamDiscussion{} + resp, err := s.client.Do(ctx, req, teamDiscussion) + if err != nil { + return nil, resp, err + } + + return teamDiscussion, resp, nil +} + +// EditDiscussion edits the title and body text of a discussion post. +// Authenticated user must grant write:discussion scope. +// User is allowed to change Title and Body of a discussion only. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussions/#edit-a-discussion +func (s *TeamsService) EditDiscussion(ctx context.Context, teamID int64, discussionNumber int, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber) + req, err := s.client.NewRequest("PATCH", u, discussion) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + teamDiscussion := &TeamDiscussion{} + resp, err := s.client.Do(ctx, req, teamDiscussion) + if err != nil { + return nil, resp, err + } + + return teamDiscussion, resp, nil +} + +// DeleteDiscussion deletes a discussion from team's page. +// Authenticated user must grant write:discussion scope. +// +// GitHub API docs: https://developer.github.com/v3/teams/discussions/#delete-a-discussion +func (s *TeamsService) DeleteDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*Response, error) { + u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/teams_discussions_test.go b/vendor/github.com/google/go-github/github/teams_discussions_test.go new file mode 100644 index 000000000..c588c2289 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_discussions_test.go @@ -0,0 +1,212 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" + "time" +) + +func TestTeamsService_ListDiscussions(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + testFormValues(t, r, values{ + "direction": "desc", + }) + fmt.Fprintf(w, + `[ + { + "author": { + "login": "author", + "id": 0, + "avatar_url": "https://avatars1.githubusercontent.com/u/0?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/author", + "html_url": "https://github.com/author", + "followers_url": "https://api.github.com/users/author/followers", + "following_url": "https://api.github.com/users/author/following{/other_user}", + "gists_url": "https://api.github.com/users/author/gists{/gist_id}", + "starred_url": "https://api.github.com/users/author/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/author/subscriptions", + "organizations_url": "https://api.github.com/users/author/orgs", + "repos_url": "https://api.github.com/users/author/repos", + "events_url": "https://api.github.com/users/author/events{/privacy}", + "received_events_url": "https://api.github.com/users/author/received_events", + "type": "User", + "site_admin": false + }, + "body": "test", + "body_html": "

test

", + "body_version": "version", + "comments_count": 1, + "comments_url": "https://api.github.com/teams/2/discussions/3/comments", + "created_at": "2018-01-01T00:00:00Z", + "last_edited_at": null, + "html_url": "https://github.com/orgs/1/teams/2/discussions/3", + "node_id": "node", + "number": 3, + "pinned": false, + "private": false, + "team_url": "https://api.github.com/teams/2", + "title": "test", + "updated_at": "2018-01-01T00:00:00Z", + "url": "https://api.github.com/teams/2/discussions/3" + } + ]`) + }) + discussions, _, err := client.Teams.ListDiscussions(context.Background(), 2, &DiscussionListOptions{"desc"}) + if err != nil { + t.Errorf("Teams.ListDiscussions returned error: %v", err) + } + + want := []*TeamDiscussion{ + { + Author: &User{ + Login: String("author"), + ID: Int64(0), + AvatarURL: String("https://avatars1.githubusercontent.com/u/0?v=4"), + GravatarID: String(""), + URL: String("https://api.github.com/users/author"), + HTMLURL: String("https://github.com/author"), + FollowersURL: String("https://api.github.com/users/author/followers"), + FollowingURL: String("https://api.github.com/users/author/following{/other_user}"), + GistsURL: String("https://api.github.com/users/author/gists{/gist_id}"), + StarredURL: String("https://api.github.com/users/author/starred{/owner}{/repo}"), + SubscriptionsURL: String("https://api.github.com/users/author/subscriptions"), + OrganizationsURL: String("https://api.github.com/users/author/orgs"), + ReposURL: String("https://api.github.com/users/author/repos"), + EventsURL: String("https://api.github.com/users/author/events{/privacy}"), + ReceivedEventsURL: String("https://api.github.com/users/author/received_events"), + Type: String("User"), + SiteAdmin: Bool(false), + }, + Body: String("test"), + BodyHTML: String("

test

"), + BodyVersion: String("version"), + CommentsCount: Int(1), + CommentsURL: String("https://api.github.com/teams/2/discussions/3/comments"), + CreatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + LastEditedAt: nil, + HTMLURL: String("https://github.com/orgs/1/teams/2/discussions/3"), + NodeID: String("node"), + Number: Int(3), + Pinned: Bool(false), + Private: Bool(false), + TeamURL: String("https://api.github.com/teams/2"), + Title: String("test"), + UpdatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + URL: String("https://api.github.com/teams/2/discussions/3"), + }, + } + if !reflect.DeepEqual(discussions, want) { + t.Errorf("Teams.ListDiscussions returned %+v, want %+v", discussions, want) + } +} + +func TestTeamsService_GetDiscussion(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions/3", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + fmt.Fprint(w, `{"number":3}`) + }) + + discussion, _, err := client.Teams.GetDiscussion(context.Background(), 2, 3) + if err != nil { + t.Errorf("Teams.GetDiscussion returned error: %v", err) + } + + want := &TeamDiscussion{Number: Int(3)} + if !reflect.DeepEqual(discussion, want) { + t.Errorf("Teams.GetDiscussion returned %+v, want %+v", discussion, want) + } +} + +func TestTeamsService_CreateDiscussion(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := TeamDiscussion{Title: String("c_t"), Body: String("c_b")} + + mux.HandleFunc("/teams/2/discussions", func(w http.ResponseWriter, r *http.Request) { + v := new(TeamDiscussion) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"number":3}`) + }) + + comment, _, err := client.Teams.CreateDiscussion(context.Background(), 2, input) + if err != nil { + t.Errorf("Teams.CreateDiscussion returned error: %v", err) + } + + want := &TeamDiscussion{Number: Int(3)} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Teams.CreateDiscussion returned %+v, want %+v", comment, want) + } +} + +func TestTeamsService_EditDiscussion(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := TeamDiscussion{Title: String("e_t"), Body: String("e_b")} + + mux.HandleFunc("/teams/2/discussions/3", func(w http.ResponseWriter, r *http.Request) { + v := new(TeamDiscussion) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"number":3}`) + }) + + comment, _, err := client.Teams.EditDiscussion(context.Background(), 2, 3, input) + if err != nil { + t.Errorf("Teams.EditDiscussion returned error: %v", err) + } + + want := &TeamDiscussion{Number: Int(3)} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Teams.EditDiscussion returned %+v, want %+v", comment, want) + } +} + +func TestTeamsService_DeleteDiscussion(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/2/discussions/3", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeTeamDiscussionsPreview) + }) + + _, err := client.Teams.DeleteDiscussion(context.Background(), 2, 3) + if err != nil { + t.Errorf("Teams.DeleteDiscussion returned error: %v", err) + } +} diff --git a/vendor/github.com/google/go-github/github/teams_members.go b/vendor/github.com/google/go-github/github/teams_members.go new file mode 100644 index 000000000..d5cfa0dc7 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_members.go @@ -0,0 +1,174 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// TeamListTeamMembersOptions specifies the optional parameters to the +// TeamsService.ListTeamMembers method. +type TeamListTeamMembersOptions struct { + // Role filters members returned by their role in the team. Possible + // values are "all", "member", "maintainer". Default is "all". + Role string `url:"role,omitempty"` + + ListOptions +} + +// ListTeamMembers lists all of the users who are members of the specified +// team. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#list-team-members +func (s *TeamsService) ListTeamMembers(ctx context.Context, team int64, opt *TeamListTeamMembersOptions) ([]*User, *Response, error) { + u := fmt.Sprintf("teams/%v/members", team) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + var members []*User + resp, err := s.client.Do(ctx, req, &members) + if err != nil { + return nil, resp, err + } + + return members, resp, nil +} + +// IsTeamMember checks if a user is a member of the specified team. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#get-team-member +// +// Deprecated: This API has been marked as deprecated in the Github API docs, +// TeamsService.GetTeamMembership method should be used instead. +func (s *TeamsService) IsTeamMember(ctx context.Context, team int64, user string) (bool, *Response, error) { + u := fmt.Sprintf("teams/%v/members/%v", team, user) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return false, nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + member, err := parseBoolResponse(err) + return member, resp, err +} + +// GetTeamMembership returns the membership status for a user in a team. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#get-team-membership +func (s *TeamsService) GetTeamMembership(ctx context.Context, team int64, user string) (*Membership, *Response, error) { + u := fmt.Sprintf("teams/%v/memberships/%v", team, user) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", mediaTypeNestedTeamsPreview) + + t := new(Membership) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// TeamAddTeamMembershipOptions specifies the optional +// parameters to the TeamsService.AddTeamMembership method. +type TeamAddTeamMembershipOptions struct { + // Role specifies the role the user should have in the team. Possible + // values are: + // member - a normal member of the team + // maintainer - a team maintainer. Able to add/remove other team + // members, promote other team members to team + // maintainer, and edit the team’s name and description + // + // Default value is "member". + Role string `json:"role,omitempty"` +} + +// AddTeamMembership adds or invites a user to a team. +// +// In order to add a membership between a user and a team, the authenticated +// user must have 'admin' permissions to the team or be an owner of the +// organization that the team is associated with. +// +// If the user is already a part of the team's organization (meaning they're on +// at least one other team in the organization), this endpoint will add the +// user to the team. +// +// If the user is completely unaffiliated with the team's organization (meaning +// they're on none of the organization's teams), this endpoint will send an +// invitation to the user via email. This newly-created membership will be in +// the "pending" state until the user accepts the invitation, at which point +// the membership will transition to the "active" state and the user will be +// added as a member of the team. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#add-or-update-team-membership +func (s *TeamsService) AddTeamMembership(ctx context.Context, team int64, user string, opt *TeamAddTeamMembershipOptions) (*Membership, *Response, error) { + u := fmt.Sprintf("teams/%v/memberships/%v", team, user) + req, err := s.client.NewRequest("PUT", u, opt) + if err != nil { + return nil, nil, err + } + + t := new(Membership) + resp, err := s.client.Do(ctx, req, t) + if err != nil { + return nil, resp, err + } + + return t, resp, nil +} + +// RemoveTeamMembership removes a user from a team. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#remove-team-membership +func (s *TeamsService) RemoveTeamMembership(ctx context.Context, team int64, user string) (*Response, error) { + u := fmt.Sprintf("teams/%v/memberships/%v", team, user) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// ListPendingTeamInvitations get pending invitaion list in team. +// Warning: The API may change without advance notice during the preview period. +// Preview features are not supported for production use. +// +// GitHub API docs: https://developer.github.com/v3/teams/members/#list-pending-team-invitations +func (s *TeamsService) ListPendingTeamInvitations(ctx context.Context, team int64, opt *ListOptions) ([]*Invitation, *Response, error) { + u := fmt.Sprintf("teams/%v/invitations", team) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var pendingInvitations []*Invitation + resp, err := s.client.Do(ctx, req, &pendingInvitations) + if err != nil { + return nil, resp, err + } + + return pendingInvitations, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/teams_members_test.go b/vendor/github.com/google/go-github/github/teams_members_test.go new file mode 100644 index 000000000..2489da0e2 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_members_test.go @@ -0,0 +1,167 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestTeamsService__ListTeamMembers(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + testFormValues(t, r, values{"role": "member", "page": "2"}) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &TeamListTeamMembersOptions{Role: "member", ListOptions: ListOptions{Page: 2}} + members, _, err := client.Teams.ListTeamMembers(context.Background(), 1, opt) + if err != nil { + t.Errorf("Teams.ListTeamMembers returned error: %v", err) + } + + want := []*User{{ID: Int64(1)}} + if !reflect.DeepEqual(members, want) { + t.Errorf("Teams.ListTeamMembers returned %+v, want %+v", members, want) + } +} + +func TestTeamsService__IsTeamMember_true(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + }) + + member, _, err := client.Teams.IsTeamMember(context.Background(), 1, "u") + if err != nil { + t.Errorf("Teams.IsTeamMember returned error: %v", err) + } + if want := true; member != want { + t.Errorf("Teams.IsTeamMember returned %+v, want %+v", member, want) + } +} + +// ensure that a 404 response is interpreted as "false" and not an error +func TestTeamsService__IsTeamMember_false(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusNotFound) + }) + + member, _, err := client.Teams.IsTeamMember(context.Background(), 1, "u") + if err != nil { + t.Errorf("Teams.IsTeamMember returned error: %+v", err) + } + if want := false; member != want { + t.Errorf("Teams.IsTeamMember returned %+v, want %+v", member, want) + } +} + +// ensure that a 400 response is interpreted as an actual error, and not simply +// as "false" like the above case of a 404 +func TestTeamsService__IsTeamMember_error(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + http.Error(w, "BadRequest", http.StatusBadRequest) + }) + + member, _, err := client.Teams.IsTeamMember(context.Background(), 1, "u") + if err == nil { + t.Errorf("Expected HTTP 400 response") + } + if want := false; member != want { + t.Errorf("Teams.IsTeamMember returned %+v, want %+v", member, want) + } +} + +func TestTeamsService__IsTeamMember_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Teams.IsTeamMember(context.Background(), 1, "%") + testURLParseError(t, err) +} + +func TestTeamsService__GetTeamMembership(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + fmt.Fprint(w, `{"url":"u", "state":"active"}`) + }) + + membership, _, err := client.Teams.GetTeamMembership(context.Background(), 1, "u") + if err != nil { + t.Errorf("Teams.GetTeamMembership returned error: %v", err) + } + + want := &Membership{URL: String("u"), State: String("active")} + if !reflect.DeepEqual(membership, want) { + t.Errorf("Teams.GetTeamMembership returned %+v, want %+v", membership, want) + } +} + +func TestTeamsService__AddTeamMembership(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + opt := &TeamAddTeamMembershipOptions{Role: "maintainer"} + + mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { + v := new(TeamAddTeamMembershipOptions) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PUT") + if !reflect.DeepEqual(v, opt) { + t.Errorf("Request body = %+v, want %+v", v, opt) + } + + fmt.Fprint(w, `{"url":"u", "state":"pending"}`) + }) + + membership, _, err := client.Teams.AddTeamMembership(context.Background(), 1, "u", opt) + if err != nil { + t.Errorf("Teams.AddTeamMembership returned error: %v", err) + } + + want := &Membership{URL: String("u"), State: String("pending")} + if !reflect.DeepEqual(membership, want) { + t.Errorf("Teams.AddTeamMembership returned %+v, want %+v", membership, want) + } +} + +func TestTeamsService__RemoveTeamMembership(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Teams.RemoveTeamMembership(context.Background(), 1, "u") + if err != nil { + t.Errorf("Teams.RemoveTeamMembership returned error: %v", err) + } +} diff --git a/vendor/github.com/google/go-github/github/teams_test.go b/vendor/github.com/google/go-github/github/teams_test.go new file mode 100644 index 000000000..89708b4f5 --- /dev/null +++ b/vendor/github.com/google/go-github/github/teams_test.go @@ -0,0 +1,465 @@ +// Copyright 2018 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "strings" + "testing" + "time" +) + +func TestTeamsService_ListTeams(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + testFormValues(t, r, values{"page": "2"}) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 2} + teams, _, err := client.Teams.ListTeams(context.Background(), "o", opt) + if err != nil { + t.Errorf("Teams.ListTeams returned error: %v", err) + } + + want := []*Team{{ID: Int64(1)}} + if !reflect.DeepEqual(teams, want) { + t.Errorf("Teams.ListTeams returned %+v, want %+v", teams, want) + } +} + +func TestTeamsService_ListTeams_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Teams.ListTeams(context.Background(), "%", nil) + testURLParseError(t, err) +} + +func TestTeamsService_GetTeam(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "parent":null}`) + }) + + team, _, err := client.Teams.GetTeam(context.Background(), 1) + if err != nil { + t.Errorf("Teams.GetTeam returned error: %v", err) + } + + want := &Team{ID: Int64(1), Name: String("n"), Description: String("d"), URL: String("u"), Slug: String("s"), Permission: String("p"), LDAPDN: String("cn=n,ou=groups,dc=example,dc=com")} + if !reflect.DeepEqual(team, want) { + t.Errorf("Teams.GetTeam returned %+v, want %+v", team, want) + } +} + +func TestTeamsService_GetTeam_nestedTeams(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", + "parent": {"id":2, "name":"n", "description": "d", "parent": null}}`) + }) + + team, _, err := client.Teams.GetTeam(context.Background(), 1) + if err != nil { + t.Errorf("Teams.GetTeam returned error: %v", err) + } + + want := &Team{ID: Int64(1), Name: String("n"), Description: String("d"), URL: String("u"), Slug: String("s"), Permission: String("p"), + Parent: &Team{ID: Int64(2), Name: String("n"), Description: String("d")}, + } + if !reflect.DeepEqual(team, want) { + t.Errorf("Teams.GetTeam returned %+v, want %+v", team, want) + } +} + +func TestTeamsService_CreateTeam(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := NewTeam{Name: "n", Privacy: String("closed"), RepoNames: []string{"r"}} + + mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { + v := new(NewTeam) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + team, _, err := client.Teams.CreateTeam(context.Background(), "o", input) + if err != nil { + t.Errorf("Teams.CreateTeam returned error: %v", err) + } + + want := &Team{ID: Int64(1)} + if !reflect.DeepEqual(team, want) { + t.Errorf("Teams.CreateTeam returned %+v, want %+v", team, want) + } +} + +func TestTeamsService_CreateTeam_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Teams.CreateTeam(context.Background(), "%", NewTeam{}) + testURLParseError(t, err) +} + +func TestTeamsService_EditTeam(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := NewTeam{Name: "n", Privacy: String("closed")} + + mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { + v := new(NewTeam) + json.NewDecoder(r.Body).Decode(v) + + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + testMethod(t, r, "PATCH") + if !reflect.DeepEqual(v, &input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + team, _, err := client.Teams.EditTeam(context.Background(), 1, input) + if err != nil { + t.Errorf("Teams.EditTeam returned error: %v", err) + } + + want := &Team{ID: Int64(1)} + if !reflect.DeepEqual(team, want) { + t.Errorf("Teams.EditTeam returned %+v, want %+v", team, want) + } +} + +func TestTeamsService_DeleteTeam(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + }) + + _, err := client.Teams.DeleteTeam(context.Background(), 1) + if err != nil { + t.Errorf("Teams.DeleteTeam returned error: %v", err) + } +} + +func TestTeamsService_ListChildTeams(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/teams", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + testFormValues(t, r, values{"page": "2"}) + fmt.Fprint(w, `[{"id":2}]`) + }) + + opt := &ListOptions{Page: 2} + teams, _, err := client.Teams.ListChildTeams(context.Background(), 1, opt) + if err != nil { + t.Errorf("Teams.ListTeams returned error: %v", err) + } + + want := []*Team{{ID: Int64(2)}} + if !reflect.DeepEqual(teams, want) { + t.Errorf("Teams.ListTeams returned %+v, want %+v", teams, want) + } +} + +func TestTeamsService_ListTeamRepos(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeNestedTeamsPreview} + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) + testFormValues(t, r, values{"page": "2"}) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 2} + members, _, err := client.Teams.ListTeamRepos(context.Background(), 1, opt) + if err != nil { + t.Errorf("Teams.ListTeamRepos returned error: %v", err) + } + + want := []*Repository{{ID: Int64(1)}} + if !reflect.DeepEqual(members, want) { + t.Errorf("Teams.ListTeamRepos returned %+v, want %+v", members, want) + } +} + +func TestTeamsService_IsTeamRepo_true(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + acceptHeaders := []string{mediaTypeOrgPermissionRepo, mediaTypeNestedTeamsPreview} + testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", ")) + fmt.Fprint(w, `{"id":1}`) + }) + + repo, _, err := client.Teams.IsTeamRepo(context.Background(), 1, "o", "r") + if err != nil { + t.Errorf("Teams.IsTeamRepo returned error: %v", err) + } + + want := &Repository{ID: Int64(1)} + if !reflect.DeepEqual(repo, want) { + t.Errorf("Teams.IsTeamRepo returned %+v, want %+v", repo, want) + } +} + +func TestTeamsService_IsTeamRepo_false(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusNotFound) + }) + + repo, resp, err := client.Teams.IsTeamRepo(context.Background(), 1, "o", "r") + if err == nil { + t.Errorf("Expected HTTP 404 response") + } + if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want { + t.Errorf("Teams.IsTeamRepo returned status %d, want %d", got, want) + } + if repo != nil { + t.Errorf("Teams.IsTeamRepo returned %+v, want nil", repo) + } +} + +func TestTeamsService_IsTeamRepo_error(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + http.Error(w, "BadRequest", http.StatusBadRequest) + }) + + repo, resp, err := client.Teams.IsTeamRepo(context.Background(), 1, "o", "r") + if err == nil { + t.Errorf("Expected HTTP 400 response") + } + if got, want := resp.Response.StatusCode, http.StatusBadRequest; got != want { + t.Errorf("Teams.IsTeamRepo returned status %d, want %d", got, want) + } + if repo != nil { + t.Errorf("Teams.IsTeamRepo returned %+v, want nil", repo) + } +} + +func TestTeamsService_IsTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, _, err := client.Teams.IsTeamRepo(context.Background(), 1, "%", "r") + testURLParseError(t, err) +} + +func TestTeamsService_AddTeamRepo(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + opt := &TeamAddTeamRepoOptions{Permission: "admin"} + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + v := new(TeamAddTeamRepoOptions) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PUT") + if !reflect.DeepEqual(v, opt) { + t.Errorf("Request body = %+v, want %+v", v, opt) + } + + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Teams.AddTeamRepo(context.Background(), 1, "o", "r", opt) + if err != nil { + t.Errorf("Teams.AddTeamRepo returned error: %v", err) + } +} + +func TestTeamsService_AddTeamRepo_noAccess(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + w.WriteHeader(http.StatusUnprocessableEntity) + }) + + _, err := client.Teams.AddTeamRepo(context.Background(), 1, "o", "r", nil) + if err == nil { + t.Errorf("Expcted error to be returned") + } +} + +func TestTeamsService_AddTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, err := client.Teams.AddTeamRepo(context.Background(), 1, "%", "r", nil) + testURLParseError(t, err) +} + +func TestTeamsService_RemoveTeamRepo(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Teams.RemoveTeamRepo(context.Background(), 1, "o", "r") + if err != nil { + t.Errorf("Teams.RemoveTeamRepo returned error: %v", err) + } +} + +func TestTeamsService_RemoveTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + + _, err := client.Teams.RemoveTeamRepo(context.Background(), 1, "%", "r") + testURLParseError(t, err) +} + +func TestTeamsService_ListUserTeams(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/user/teams", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview) + testFormValues(t, r, values{"page": "1"}) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1} + teams, _, err := client.Teams.ListUserTeams(context.Background(), opt) + if err != nil { + t.Errorf("Teams.ListUserTeams returned error: %v", err) + } + + want := []*Team{{ID: Int64(1)}} + if !reflect.DeepEqual(teams, want) { + t.Errorf("Teams.ListUserTeams returned %+v, want %+v", teams, want) + } +} + +func TestTeamsService_ListPendingTeamInvitations(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/teams/1/invitations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "1"}) + fmt.Fprint(w, `[ + { + "id": 1, + "login": "monalisa", + "email": "octocat@github.com", + "role": "direct_member", + "created_at": "2017-01-21T00:00:00Z", + "inviter": { + "login": "other_user", + "id": 1, + "avatar_url": "https://github.com/images/error/other_user_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/other_user", + "html_url": "https://github.com/other_user", + "followers_url": "https://api.github.com/users/other_user/followers", + "following_url": "https://api.github.com/users/other_user/following/other_user", + "gists_url": "https://api.github.com/users/other_user/gists/gist_id", + "starred_url": "https://api.github.com/users/other_user/starred/owner/repo", + "subscriptions_url": "https://api.github.com/users/other_user/subscriptions", + "organizations_url": "https://api.github.com/users/other_user/orgs", + "repos_url": "https://api.github.com/users/other_user/repos", + "events_url": "https://api.github.com/users/other_user/events/privacy", + "received_events_url": "https://api.github.com/users/other_user/received_events/privacy", + "type": "User", + "site_admin": false + } + } + ]`) + }) + + opt := &ListOptions{Page: 1} + invitations, _, err := client.Teams.ListPendingTeamInvitations(context.Background(), 1, opt) + if err != nil { + t.Errorf("Teams.ListPendingTeamInvitations returned error: %v", err) + } + + createdAt := time.Date(2017, time.January, 21, 0, 0, 0, 0, time.UTC) + want := []*Invitation{ + { + ID: Int64(1), + Login: String("monalisa"), + Email: String("octocat@github.com"), + Role: String("direct_member"), + CreatedAt: &createdAt, + Inviter: &User{ + Login: String("other_user"), + ID: Int64(1), + AvatarURL: String("https://github.com/images/error/other_user_happy.gif"), + GravatarID: String(""), + URL: String("https://api.github.com/users/other_user"), + HTMLURL: String("https://github.com/other_user"), + FollowersURL: String("https://api.github.com/users/other_user/followers"), + FollowingURL: String("https://api.github.com/users/other_user/following/other_user"), + GistsURL: String("https://api.github.com/users/other_user/gists/gist_id"), + StarredURL: String("https://api.github.com/users/other_user/starred/owner/repo"), + SubscriptionsURL: String("https://api.github.com/users/other_user/subscriptions"), + OrganizationsURL: String("https://api.github.com/users/other_user/orgs"), + ReposURL: String("https://api.github.com/users/other_user/repos"), + EventsURL: String("https://api.github.com/users/other_user/events/privacy"), + ReceivedEventsURL: String("https://api.github.com/users/other_user/received_events/privacy"), + Type: String("User"), + SiteAdmin: Bool(false), + }, + }} + + if !reflect.DeepEqual(invitations, want) { + t.Errorf("Teams.ListPendingTeamInvitations returned %+v, want %+v", invitations, want) + } +} diff --git a/vendor/github.com/google/go-github/github/timestamp.go b/vendor/github.com/google/go-github/github/timestamp.go index a1c1554a3..90929d575 100644 --- a/vendor/github.com/google/go-github/github/timestamp.go +++ b/vendor/github.com/google/go-github/github/timestamp.go @@ -28,9 +28,9 @@ func (t *Timestamp) UnmarshalJSON(data []byte) (err error) { str := string(data) i, err := strconv.ParseInt(str, 10, 64) if err == nil { - (*t).Time = time.Unix(i, 0) + t.Time = time.Unix(i, 0) } else { - (*t).Time, err = time.Parse(`"`+time.RFC3339+`"`, str) + t.Time, err = time.Parse(`"`+time.RFC3339+`"`, str) } return } diff --git a/vendor/github.com/google/go-github/github/timestamp_test.go b/vendor/github.com/google/go-github/github/timestamp_test.go index ea7fa0eb5..dc09eaf99 100644 --- a/vendor/github.com/google/go-github/github/timestamp_test.go +++ b/vendor/github.com/google/go-github/github/timestamp_test.go @@ -20,7 +20,7 @@ const ( ) var ( - referenceTime = time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC) + referenceTime = time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC) unixOrigin = time.Unix(0, 0).In(time.UTC) ) diff --git a/vendor/github.com/google/go-github/github/users.go b/vendor/github.com/google/go-github/github/users.go index 83cfb45b5..a4f74904c 100644 --- a/vendor/github.com/google/go-github/github/users.go +++ b/vendor/github.com/google/go-github/github/users.go @@ -18,33 +18,35 @@ type UsersService service // User represents a GitHub user. type User struct { - Login *string `json:"login,omitempty"` - ID *int `json:"id,omitempty"` - AvatarURL *string `json:"avatar_url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - GravatarID *string `json:"gravatar_id,omitempty"` - Name *string `json:"name,omitempty"` - Company *string `json:"company,omitempty"` - Blog *string `json:"blog,omitempty"` - Location *string `json:"location,omitempty"` - Email *string `json:"email,omitempty"` - Hireable *bool `json:"hireable,omitempty"` - Bio *string `json:"bio,omitempty"` - PublicRepos *int `json:"public_repos,omitempty"` - PublicGists *int `json:"public_gists,omitempty"` - Followers *int `json:"followers,omitempty"` - Following *int `json:"following,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - SuspendedAt *Timestamp `json:"suspended_at,omitempty"` - Type *string `json:"type,omitempty"` - SiteAdmin *bool `json:"site_admin,omitempty"` - TotalPrivateRepos *int `json:"total_private_repos,omitempty"` - OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"` - PrivateGists *int `json:"private_gists,omitempty"` - DiskUsage *int `json:"disk_usage,omitempty"` - Collaborators *int `json:"collaborators,omitempty"` - Plan *Plan `json:"plan,omitempty"` + Login *string `json:"login,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + AvatarURL *string `json:"avatar_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + GravatarID *string `json:"gravatar_id,omitempty"` + Name *string `json:"name,omitempty"` + Company *string `json:"company,omitempty"` + Blog *string `json:"blog,omitempty"` + Location *string `json:"location,omitempty"` + Email *string `json:"email,omitempty"` + Hireable *bool `json:"hireable,omitempty"` + Bio *string `json:"bio,omitempty"` + PublicRepos *int `json:"public_repos,omitempty"` + PublicGists *int `json:"public_gists,omitempty"` + Followers *int `json:"followers,omitempty"` + Following *int `json:"following,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + SuspendedAt *Timestamp `json:"suspended_at,omitempty"` + Type *string `json:"type,omitempty"` + SiteAdmin *bool `json:"site_admin,omitempty"` + TotalPrivateRepos *int `json:"total_private_repos,omitempty"` + OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"` + PrivateGists *int `json:"private_gists,omitempty"` + DiskUsage *int `json:"disk_usage,omitempty"` + Collaborators *int `json:"collaborators,omitempty"` + TwoFactorAuthentication *bool `json:"two_factor_authentication,omitempty"` + Plan *Plan `json:"plan,omitempty"` // API URLs URL *string `json:"url,omitempty"` @@ -75,6 +77,7 @@ func (u User) String() string { // user. // // GitHub API docs: https://developer.github.com/v3/users/#get-a-single-user +// and: https://developer.github.com/v3/users/#get-the-authenticated-user func (s *UsersService) Get(ctx context.Context, user string) (*User, *Response, error) { var u string if user != "" { @@ -99,7 +102,7 @@ func (s *UsersService) Get(ctx context.Context, user string) (*User, *Response, // GetByID fetches a user. // // Note: GetByID uses the undocumented GitHub API endpoint /user/:id. -func (s *UsersService) GetByID(ctx context.Context, id int) (*User, *Response, error) { +func (s *UsersService) GetByID(ctx context.Context, id int64) (*User, *Response, error) { u := fmt.Sprintf("user/%d", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -134,12 +137,65 @@ func (s *UsersService) Edit(ctx context.Context, user *User) (*User, *Response, return uResp, resp, nil } +// HovercardOptions specifies optional parameters to the UsersService.GetHovercard +// method. +type HovercardOptions struct { + // SubjectType specifies the additional information to be received about the hovercard. + // Possible values are: organization, repository, issue, pull_request. (Required when using subject_id.) + SubjectType string `url:"subject_type"` + + // SubjectID specifies the ID for the SubjectType. (Required when using subject_type.) + SubjectID string `url:"subject_id"` +} + +// Hovercard represents hovercard information about a user. +type Hovercard struct { + Contexts []*UserContext `json:"contexts,omitempty"` +} + +// UserContext represents the contextual information about user. +type UserContext struct { + Message *string `json:"message,omitempty"` + Octicon *string `json:"octicon,omitempty"` +} + +// GetHovercard fetches contextual information about user. It requires authentication +// via Basic Auth or via OAuth with the repo scope. +// +// GitHub API docs: https://developer.github.com/v3/users/#get-contextual-information-about-a-user +func (s *UsersService) GetHovercard(ctx context.Context, user string, opt *HovercardOptions) (*Hovercard, *Response, error) { + u := fmt.Sprintf("users/%v/hovercard", user) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeHovercardPreview) + + hc := new(Hovercard) + resp, err := s.client.Do(ctx, req, hc) + if err != nil { + return nil, resp, err + } + + return hc, resp, nil +} + // UserListOptions specifies optional parameters to the UsersService.ListAll // method. type UserListOptions struct { // ID of the last user seen - Since int `url:"since,omitempty"` + Since int64 `url:"since,omitempty"` + // Note: Pagination is powered exclusively by the Since parameter, + // ListOptions.Page has no effect. + // ListOptions.PerPage controls an undocumented GitHub API parameter. ListOptions } @@ -199,7 +255,7 @@ func (s *UsersService) ListInvitations(ctx context.Context, opt *ListOptions) ([ // authenticated user. // // GitHub API docs: https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation -func (s *UsersService) AcceptInvitation(ctx context.Context, invitationID int) (*Response, error) { +func (s *UsersService) AcceptInvitation(ctx context.Context, invitationID int64) (*Response, error) { u := fmt.Sprintf("user/repository_invitations/%v", invitationID) req, err := s.client.NewRequest("PATCH", u, nil) if err != nil { @@ -216,7 +272,7 @@ func (s *UsersService) AcceptInvitation(ctx context.Context, invitationID int) ( // authenticated user. // // GitHub API docs: https://developer.github.com/v3/repos/invitations/#decline-a-repository-invitation -func (s *UsersService) DeclineInvitation(ctx context.Context, invitationID int) (*Response, error) { +func (s *UsersService) DeclineInvitation(ctx context.Context, invitationID int64) (*Response, error) { u := fmt.Sprintf("user/repository_invitations/%v", invitationID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/users_administration_test.go b/vendor/github.com/google/go-github/github/users_administration_test.go index 8f02b88ce..4b0955e90 100644 --- a/vendor/github.com/google/go-github/github/users_administration_test.go +++ b/vendor/github.com/google/go-github/github/users_administration_test.go @@ -12,7 +12,7 @@ import ( ) func TestUsersService_PromoteSiteAdmin(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { @@ -27,7 +27,7 @@ func TestUsersService_PromoteSiteAdmin(t *testing.T) { } func TestUsersService_DemoteSiteAdmin(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { @@ -42,7 +42,7 @@ func TestUsersService_DemoteSiteAdmin(t *testing.T) { } func TestUsersService_Suspend(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func TestUsersService_Suspend(t *testing.T) { } func TestUsersService_Unsuspend(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/users_blocking_test.go b/vendor/github.com/google/go-github/github/users_blocking_test.go index ea7a8abdc..83e8e30c8 100644 --- a/vendor/github.com/google/go-github/github/users_blocking_test.go +++ b/vendor/github.com/google/go-github/github/users_blocking_test.go @@ -14,7 +14,7 @@ import ( ) func TestUsersService_ListBlockedUsers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestUsersService_ListBlockedUsers(t *testing.T) { } func TestUsersService_IsBlocked(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestUsersService_IsBlocked(t *testing.T) { } func TestUsersService_BlockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -74,7 +74,7 @@ func TestUsersService_BlockUser(t *testing.T) { } func TestUsersService_UnblockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/users_emails_test.go b/vendor/github.com/google/go-github/github/users_emails_test.go index 3f8176a00..3f72b409b 100644 --- a/vendor/github.com/google/go-github/github/users_emails_test.go +++ b/vendor/github.com/google/go-github/github/users_emails_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) { @@ -41,7 +41,7 @@ func TestUsersService_ListEmails(t *testing.T) { } func TestUsersService_AddEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"new@example.com"} @@ -73,7 +73,7 @@ func TestUsersService_AddEmails(t *testing.T) { } func TestUsersService_DeleteEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"user@example.com"} diff --git a/vendor/github.com/google/go-github/github/users_followers_test.go b/vendor/github.com/google/go-github/github/users_followers_test.go index 688af2c44..777fe8014 100644 --- a/vendor/github.com/google/go-github/github/users_followers_test.go +++ b/vendor/github.com/google/go-github/github/users_followers_test.go @@ -14,7 +14,7 @@ import ( ) func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/followers", func(w http.ResponseWriter, r *http.Request) { @@ -29,14 +29,14 @@ func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) { t.Errorf("Users.ListFollowers returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(users, want) { t.Errorf("Users.ListFollowers returned %+v, want %+v", users, want) } } func TestUsersService_ListFollowers_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/followers", func(w http.ResponseWriter, r *http.Request) { @@ -49,19 +49,22 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) { t.Errorf("Users.ListFollowers returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(users, want) { t.Errorf("Users.ListFollowers returned %+v, want %+v", users, want) } } func TestUsersService_ListFollowers_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListFollowers(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following", func(w http.ResponseWriter, r *http.Request) { @@ -76,14 +79,14 @@ func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) { t.Errorf("Users.ListFollowing returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(users, want) { t.Errorf("Users.ListFollowing returned %+v, want %+v", users, want) } } func TestUsersService_ListFollowing_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following", func(w http.ResponseWriter, r *http.Request) { @@ -96,19 +99,22 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) { t.Errorf("Users.ListFollowing returned error: %v", err) } - want := []*User{{ID: Int(1)}} + want := []*User{{ID: Int64(1)}} if !reflect.DeepEqual(users, want) { t.Errorf("Users.ListFollowing returned %+v, want %+v", users, want) } } func TestUsersService_ListFollowing_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListFollowing(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_IsFollowing_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -126,7 +132,7 @@ func TestUsersService_IsFollowing_authenticatedUser(t *testing.T) { } func TestUsersService_IsFollowing_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -144,7 +150,7 @@ func TestUsersService_IsFollowing_specifiedUser(t *testing.T) { } func TestUsersService_IsFollowing_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -162,7 +168,7 @@ func TestUsersService_IsFollowing_false(t *testing.T) { } func TestUsersService_IsFollowing_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -180,12 +186,15 @@ func TestUsersService_IsFollowing_error(t *testing.T) { } func TestUsersService_IsFollowing_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.IsFollowing(context.Background(), "%", "%") testURLParseError(t, err) } func TestUsersService_Follow(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/u", func(w http.ResponseWriter, r *http.Request) { @@ -199,12 +208,15 @@ func TestUsersService_Follow(t *testing.T) { } func TestUsersService_Follow_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Users.Follow(context.Background(), "%") testURLParseError(t, err) } func TestUsersService_Unfollow(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/u", func(w http.ResponseWriter, r *http.Request) { @@ -218,6 +230,9 @@ func TestUsersService_Unfollow(t *testing.T) { } func TestUsersService_Unfollow_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Users.Unfollow(context.Background(), "%") testURLParseError(t, err) } diff --git a/vendor/github.com/google/go-github/github/users_gpg_keys.go b/vendor/github.com/google/go-github/github/users_gpg_keys.go index 3e95fb446..d8bbc5201 100644 --- a/vendor/github.com/google/go-github/github/users_gpg_keys.go +++ b/vendor/github.com/google/go-github/github/users_gpg_keys.go @@ -15,8 +15,8 @@ import ( // // https://developer.github.com/changes/2016-04-04-git-signing-api-preview/ type GPGKey struct { - ID *int `json:"id,omitempty"` - PrimaryKeyID *int `json:"primary_key_id,omitempty"` + ID *int64 `json:"id,omitempty"` + PrimaryKeyID *int64 `json:"primary_key_id,omitempty"` KeyID *string `json:"key_id,omitempty"` PublicKey *string `json:"public_key,omitempty"` Emails []GPGEmail `json:"emails,omitempty"` @@ -78,7 +78,7 @@ func (s *UsersService) ListGPGKeys(ctx context.Context, user string, opt *ListOp // via Basic Auth or via OAuth with at least read:gpg_key scope. // // GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key -func (s *UsersService) GetGPGKey(ctx context.Context, id int) (*GPGKey, *Response, error) { +func (s *UsersService) GetGPGKey(ctx context.Context, id int64) (*GPGKey, *Response, error) { u := fmt.Sprintf("user/gpg_keys/%v", id) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -126,7 +126,7 @@ func (s *UsersService) CreateGPGKey(ctx context.Context, armoredPublicKey string // via OAuth with at least admin:gpg_key scope. // // GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#delete-a-gpg-key -func (s *UsersService) DeleteGPGKey(ctx context.Context, id int) (*Response, error) { +func (s *UsersService) DeleteGPGKey(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("user/gpg_keys/%v", id) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/vendor/github.com/google/go-github/github/users_gpg_keys_test.go b/vendor/github.com/google/go-github/github/users_gpg_keys_test.go index f4180df98..ca0207eb4 100644 --- a/vendor/github.com/google/go-github/github/users_gpg_keys_test.go +++ b/vendor/github.com/google/go-github/github/users_gpg_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListGPGKeys_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys", func(w http.ResponseWriter, r *http.Request) { @@ -31,14 +31,14 @@ func TestUsersService_ListGPGKeys_authenticatedUser(t *testing.T) { t.Errorf("Users.ListGPGKeys returned error: %v", err) } - want := []*GPGKey{{ID: Int(1), PrimaryKeyID: Int(2)}} + want := []*GPGKey{{ID: Int64(1), PrimaryKeyID: Int64(2)}} if !reflect.DeepEqual(keys, want) { t.Errorf("Users.ListGPGKeys = %+v, want %+v", keys, want) } } func TestUsersService_ListGPGKeys_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/gpg_keys", func(w http.ResponseWriter, r *http.Request) { @@ -52,19 +52,22 @@ func TestUsersService_ListGPGKeys_specifiedUser(t *testing.T) { t.Errorf("Users.ListGPGKeys returned error: %v", err) } - want := []*GPGKey{{ID: Int(1), PrimaryKeyID: Int(2)}} + want := []*GPGKey{{ID: Int64(1), PrimaryKeyID: Int64(2)}} if !reflect.DeepEqual(keys, want) { t.Errorf("Users.ListGPGKeys = %+v, want %+v", keys, want) } } func TestUsersService_ListGPGKeys_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListGPGKeys(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_GetGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -78,14 +81,14 @@ func TestUsersService_GetGPGKey(t *testing.T) { t.Errorf("Users.GetGPGKey returned error: %v", err) } - want := &GPGKey{ID: Int(1)} + want := &GPGKey{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Users.GetGPGKey = %+v, want %+v", key, want) } } func TestUsersService_CreateGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := ` @@ -117,14 +120,14 @@ mQINBFcEd9kBEACo54TDbGhKlXKWMvJgecEUKPPcv7XdnpKdGb3LRw5MvFwT0V0f t.Errorf("Users.GetGPGKey returned error: %v", err) } - want := &GPGKey{ID: Int(1)} + want := &GPGKey{ID: Int64(1)} if !reflect.DeepEqual(gpgKey, want) { t.Errorf("Users.GetGPGKey = %+v, want %+v", gpgKey, want) } } func TestUsersService_DeleteGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/users_keys.go b/vendor/github.com/google/go-github/github/users_keys.go index 97ed4b861..ddc832a1e 100644 --- a/vendor/github.com/google/go-github/github/users_keys.go +++ b/vendor/github.com/google/go-github/github/users_keys.go @@ -12,7 +12,7 @@ import ( // Key represents a public SSH key used to authenticate a user or deploy script. type Key struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Key *string `json:"key,omitempty"` URL *string `json:"url,omitempty"` Title *string `json:"title,omitempty"` @@ -56,7 +56,7 @@ func (s *UsersService) ListKeys(ctx context.Context, user string, opt *ListOptio // GetKey fetches a single public key. // // GitHub API docs: https://developer.github.com/v3/users/keys/#get-a-single-public-key -func (s *UsersService) GetKey(ctx context.Context, id int) (*Key, *Response, error) { +func (s *UsersService) GetKey(ctx context.Context, id int64) (*Key, *Response, error) { u := fmt.Sprintf("user/keys/%v", id) req, err := s.client.NewRequest("GET", u, nil) @@ -96,7 +96,7 @@ func (s *UsersService) CreateKey(ctx context.Context, key *Key) (*Key, *Response // DeleteKey deletes a public key. // // GitHub API docs: https://developer.github.com/v3/users/keys/#delete-a-public-key -func (s *UsersService) DeleteKey(ctx context.Context, id int) (*Response, error) { +func (s *UsersService) DeleteKey(ctx context.Context, id int64) (*Response, error) { u := fmt.Sprintf("user/keys/%v", id) req, err := s.client.NewRequest("DELETE", u, nil) diff --git a/vendor/github.com/google/go-github/github/users_keys_test.go b/vendor/github.com/google/go-github/github/users_keys_test.go index 8554c50cd..3115fdb2e 100644 --- a/vendor/github.com/google/go-github/github/users_keys_test.go +++ b/vendor/github.com/google/go-github/github/users_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListKeys_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) { @@ -30,14 +30,14 @@ func TestUsersService_ListKeys_authenticatedUser(t *testing.T) { t.Errorf("Users.ListKeys returned error: %v", err) } - want := []*Key{{ID: Int(1)}} + want := []*Key{{ID: Int64(1)}} if !reflect.DeepEqual(keys, want) { t.Errorf("Users.ListKeys returned %+v, want %+v", keys, want) } } func TestUsersService_ListKeys_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/keys", func(w http.ResponseWriter, r *http.Request) { @@ -50,19 +50,22 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) { t.Errorf("Users.ListKeys returned error: %v", err) } - want := []*Key{{ID: Int(1)}} + want := []*Key{{ID: Int64(1)}} if !reflect.DeepEqual(keys, want) { t.Errorf("Users.ListKeys returned %+v, want %+v", keys, want) } } func TestUsersService_ListKeys_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListKeys(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_GetKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -75,14 +78,14 @@ func TestUsersService_GetKey(t *testing.T) { t.Errorf("Users.GetKey returned error: %v", err) } - want := &Key{ID: Int(1)} + want := &Key{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Users.GetKey returned %+v, want %+v", key, want) } } func TestUsersService_CreateKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -104,14 +107,14 @@ func TestUsersService_CreateKey(t *testing.T) { t.Errorf("Users.GetKey returned error: %v", err) } - want := &Key{ID: Int(1)} + want := &Key{ID: Int64(1)} if !reflect.DeepEqual(key, want) { t.Errorf("Users.GetKey returned %+v, want %+v", key, want) } } func TestUsersService_DeleteKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/users_test.go b/vendor/github.com/google/go-github/github/users_test.go index 34c239a66..b01190871 100644 --- a/vendor/github.com/google/go-github/github/users_test.go +++ b/vendor/github.com/google/go-github/github/users_test.go @@ -19,7 +19,7 @@ func TestUser_marshall(t *testing.T) { u := &User{ Login: String("l"), - ID: Int(1), + ID: Int64(1), URL: String("u"), AvatarURL: String("a"), GravatarID: String("g"), @@ -57,7 +57,7 @@ func TestUser_marshall(t *testing.T) { } func TestUsersService_Get_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { @@ -70,14 +70,14 @@ func TestUsersService_Get_authenticatedUser(t *testing.T) { t.Errorf("Users.Get returned error: %v", err) } - want := &User{ID: Int(1)} + want := &User{ID: Int64(1)} if !reflect.DeepEqual(user, want) { t.Errorf("Users.Get returned %+v, want %+v", user, want) } } func TestUsersService_Get_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u", func(w http.ResponseWriter, r *http.Request) { @@ -90,19 +90,22 @@ func TestUsersService_Get_specifiedUser(t *testing.T) { t.Errorf("Users.Get returned error: %v", err) } - want := &User{ID: Int(1)} + want := &User{ID: Int64(1)} if !reflect.DeepEqual(user, want) { t.Errorf("Users.Get returned %+v, want %+v", user, want) } } func TestUsersService_Get_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.Get(context.Background(), "%") testURLParseError(t, err) } func TestUsersService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/1", func(w http.ResponseWriter, r *http.Request) { @@ -115,14 +118,14 @@ func TestUsersService_GetByID(t *testing.T) { t.Fatalf("Users.GetByID returned error: %v", err) } - want := &User{ID: Int(1)} + want := &User{ID: Int64(1)} if !reflect.DeepEqual(user, want) { t.Errorf("Users.GetByID returned %+v, want %+v", user, want) } } func TestUsersService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &User{Name: String("n")} @@ -144,14 +147,37 @@ func TestUsersService_Edit(t *testing.T) { t.Errorf("Users.Edit returned error: %v", err) } - want := &User{ID: Int(1)} + want := &User{ID: Int64(1)} if !reflect.DeepEqual(user, want) { t.Errorf("Users.Edit returned %+v, want %+v", user, want) } } +func TestUsersService_GetHovercard(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/users/u/hovercard", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeHovercardPreview) + testFormValues(t, r, values{"subject_type": "repository", "subject_id": "20180408"}) + fmt.Fprint(w, `{"contexts": [{"message":"Owns this repository", "octicon": "repo"}]}`) + }) + + opt := &HovercardOptions{SubjectType: "repository", SubjectID: "20180408"} + hovercard, _, err := client.Users.GetHovercard(context.Background(), "u", opt) + if err != nil { + t.Errorf("Users.GetHovercard returned error: %v", err) + } + + want := &Hovercard{Contexts: []*UserContext{{Message: String("Owns this repository"), Octicon: String("repo")}}} + if !reflect.DeepEqual(hovercard, want) { + t.Errorf("Users.GetHovercard returned %+v, want %+v", hovercard, want) + } +} + func TestUsersService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { @@ -166,14 +192,14 @@ func TestUsersService_ListAll(t *testing.T) { t.Errorf("Users.Get returned error: %v", err) } - want := []*User{{ID: Int(2)}} + want := []*User{{ID: Int64(2)}} if !reflect.DeepEqual(users, want) { t.Errorf("Users.ListAll returned %+v, want %+v", users, want) } } func TestUsersService_ListInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations", func(w http.ResponseWriter, r *http.Request) { @@ -187,14 +213,14 @@ func TestUsersService_ListInvitations(t *testing.T) { t.Errorf("Users.ListInvitations returned error: %v", err) } - want := []*RepositoryInvitation{{ID: Int(1)}, {ID: Int(2)}} + want := []*RepositoryInvitation{{ID: Int64(1)}, {ID: Int64(2)}} if !reflect.DeepEqual(got, want) { t.Errorf("Users.ListInvitations = %+v, want %+v", got, want) } } func TestUsersService_ListInvitations_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations", func(w http.ResponseWriter, r *http.Request) { @@ -212,7 +238,7 @@ func TestUsersService_ListInvitations_withOptions(t *testing.T) { } } func TestUsersService_AcceptInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations/1", func(w http.ResponseWriter, r *http.Request) { @@ -227,7 +253,7 @@ func TestUsersService_AcceptInvitation(t *testing.T) { } func TestUsersService_DeclineInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/google/go-github/github/with_appengine.go b/vendor/github.com/google/go-github/github/with_appengine.go index 87a228ad7..59ce26b2e 100644 --- a/vendor/github.com/google/go-github/github/with_appengine.go +++ b/vendor/github.com/google/go-github/github/with_appengine.go @@ -6,11 +6,6 @@ // +build appengine // This file provides glue for making github work on App Engine. -// In order to get the entire github package to compile with -// Go 1.6, you will need to rewrite all the import "context" lines. -// Fortunately, this is easy with "gofmt": -// -// gofmt -w -r '"context" -> "golang.org/x/net/context"' *.go package github diff --git a/vendor/github.com/google/go-github/go.mod b/vendor/github.com/google/go-github/go.mod new file mode 100644 index 000000000..b12d7b70c --- /dev/null +++ b/vendor/github.com/google/go-github/go.mod @@ -0,0 +1,11 @@ +module github.com/google/go-github/v19 + +require ( + github.com/golang/protobuf v1.2.0 // indirect + github.com/google/go-querystring v1.0.0 + golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac + golang.org/x/net v0.0.0-20180826012351-8a410e7b638d // indirect + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be + golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87 // indirect + google.golang.org/appengine v1.1.0 +) diff --git a/vendor/github.com/google/go-github/go.sum b/vendor/github.com/google/go-github/go.sum new file mode 100644 index 000000000..058a096e3 --- /dev/null +++ b/vendor/github.com/google/go-github/go.sum @@ -0,0 +1,16 @@ +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 h1:zLTLjkaOFEFIOxY5BWLFLwh+cL8vOBW4XJ2aqLE/Tf0= +github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac h1:7d7lG9fHOLdL6jZPtnV4LpI41SbohIJ1Atq7U991dMg= +golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87 h1:GqwDwfvIpC33dK9bA1fD+JiDUNsuAiQiEkpHqUKze4o= +golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/vendor/github.com/google/go-github/test/README.md b/vendor/github.com/google/go-github/test/README.md index cb3ef5511..455795a7b 100644 --- a/vendor/github.com/google/go-github/test/README.md +++ b/vendor/github.com/google/go-github/test/README.md @@ -54,7 +54,7 @@ This test sends real network traffic to the GitHub API and will exhaust the default unregistered rate limit (60 requests per hour) very quickly. Additionally, some data is only returned for authenticated API calls. Unlike the integration tests above, these tests only read data, so it's less -imperitive that these be run using a dedicated test account (though you still +imperative that these be run using a dedicated test account (though you still really should). Run the fields tool using: diff --git a/vendor/github.com/google/go-github/test/fields/fields.go b/vendor/github.com/google/go-github/test/fields/fields.go index 7ee1f6e05..533c05221 100644 --- a/vendor/github.com/google/go-github/test/fields/fields.go +++ b/vendor/github.com/google/go-github/test/fields/fields.go @@ -25,7 +25,7 @@ import ( "reflect" "strings" - "github.com/google/go-github/github" + "github.com/google/go-github/v19/github" "golang.org/x/oauth2" ) diff --git a/vendor/github.com/google/go-github/test/integration/repos_test.go b/vendor/github.com/google/go-github/test/integration/repos_test.go index 9f3d2322f..58aa1821c 100644 --- a/vendor/github.com/google/go-github/test/integration/repos_test.go +++ b/vendor/github.com/google/go-github/test/integration/repos_test.go @@ -108,19 +108,12 @@ func TestRepositories_EditBranches(t *testing.T) { t.Fatalf("Branch %v of repo %v is already protected", "master", *repo.Name) } - // TODO: This test fails with 422 Validation Failed [{Resource: Field: Code: Message:}]. - // Someone familiar with protection requests needs to come up with - // a valid protection request that doesn't give 422 error. protectionRequest := &github.ProtectionRequest{ RequiredStatusChecks: &github.RequiredStatusChecks{ Strict: true, Contexts: []string{"continuous-integration"}, }, RequiredPullRequestReviews: &github.PullRequestReviewsEnforcementRequest{ - DismissalRestrictionsRequest: &github.DismissalRestrictionsRequest{ - Users: []string{}, - Teams: []string{}, - }, DismissStaleReviews: true, }, EnforceAdmins: true, @@ -141,13 +134,11 @@ func TestRepositories_EditBranches(t *testing.T) { Contexts: []string{"continuous-integration"}, }, RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: github.DismissalRestrictions{ - Users: []*github.User{}, - Teams: []*github.Team{}, - }, - DismissStaleReviews: true, + DismissStaleReviews: true, + RequiredApprovingReviewCount: 0, }, EnforceAdmins: &github.AdminEnforcement{ + URL: github.String("https://api.github.com/repos/" + *repo.Owner.Login + "/" + *repo.Name + "/branches/master/protection/enforce_admins"), Enabled: true, }, Restrictions: nil, diff --git a/vendor/github.com/google/go-github/test/integration/users_test.go b/vendor/github.com/google/go-github/test/integration/users_test.go index 49bd9cb2d..3c47c369a 100644 --- a/vendor/github.com/google/go-github/test/integration/users_test.go +++ b/vendor/github.com/google/go-github/test/integration/users_test.go @@ -203,7 +203,7 @@ func TestUsers_Keys(t *testing.T) { t.Fatalf("Users.ListKeys('') returned error: %v", err) } - var id int + var id int64 for _, k := range keys { if k.Key != nil && *k.Key == key { id = *k.ID