-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9348c13
Showing
31 changed files
with
2,360 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/.idea | ||
/.vscode | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: go | ||
|
||
go: | ||
- 1.12.4 | ||
|
||
install: | ||
- go get -v newreleases.io/newreleases/... | ||
|
||
before_script: | ||
- go vet -v newreleases.io/newreleases/... | ||
|
||
script: | ||
- go test -v -race newreleases.io/newreleases/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is the official list of NewReleases Go client authors for copyright purposes. | ||
|
||
Janoš Guljaš <janos@resenje.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# How to contribute | ||
|
||
We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. | ||
|
||
1. Code should be `go fmt` formatted. | ||
2. Exported types, constants, variables and functions should be documented. | ||
3. Changes must be covered with tests. | ||
4. All tests must pass constantly `go test .`. | ||
|
||
## Versioning | ||
|
||
NewReleases Go client follows semantic versioning. New functionality should be accompanied by increment to the minor version number. | ||
|
||
## Releasing | ||
|
||
Any code which is complete, tested, reviewed, and merged to master can be released. | ||
|
||
1. Update the `version` number in `newreleases.go`. | ||
2. Make a pull request with these changes. | ||
3. Once the pull request has been merged, visit [https://github.com/newreleasesio/client-go/releases](https://github.com/newreleasesio/client-go/release) and click `Draft a new release`. | ||
4. Update the `Tag version` and `Release title` field with the new NewReleases Go client version. Be sure the version has a `v` prefixed in both places, e.g. `v1.25.0`. | ||
5. Publish the release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2019, NewReleases Go client AUTHORS. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of this project nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# NewReleases API v1 Go client | ||
|
||
[![GoDoc](https://godoc.org/newreleases.io/newreleases?status.svg)](https://godoc.org/newreleases.io/newreleases) | ||
[![Build Status](https://travis-ci.org/newreleasesio/client-go.svg?branch=master)](https://travis-ci.org/newreleasesio/client-go) | ||
|
||
Package newreleases is a Go client library for accessing the [NewReleases](https://newreleases.io) v1 API. | ||
|
||
You can view the client API docs here: [https://godoc.org/newreleases.io/newreleases](https://godoc.org/newreleases.io/newreleases) | ||
|
||
You can view NewReleases API docs here: [https://newreleases.io/api/v1](https://newreleases.io/api/v1) | ||
|
||
## Installation | ||
|
||
Run `go get newreleases.io/newreleases` from command line. | ||
|
||
## Usage | ||
|
||
```go | ||
import "newreleases.io/newreleases" | ||
``` | ||
|
||
Create a new Client, then use the exposed services to access different parts of the API. | ||
|
||
## Authentication | ||
|
||
Currently, API keys is the only method of | ||
authenticating with the API. You can manage your keys | ||
at the NewReleases [API keys settings page](https://newreleases.io/settings/api-keys). | ||
|
||
You can then use your token to create a new Client. | ||
|
||
## Features | ||
|
||
This client implements all NewReleases API features. | ||
|
||
- List projects | ||
- Search projects | ||
- Get project | ||
- Add project | ||
- Update project | ||
- Delete project | ||
- List projects releases | ||
- Get project release | ||
- Get project release note | ||
- Get tracked providers | ||
- Get added Slack Channels | ||
- Get added Hangouts Chat webhooks | ||
- Get added Microsoft Teams webhooks | ||
- Get added custom Webhooks | ||
- Get auth keys | ||
|
||
## Examples | ||
|
||
To add a new project: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"newreleases.io/newreleases" | ||
) | ||
|
||
var key = "myapikey" | ||
|
||
func main() { | ||
client := newreleases.NewClient(key, nil) | ||
p, err := client.Projects.Add( | ||
context.Background(), | ||
"github", | ||
"golang/go", | ||
newreleases.ProjectOptions{ | ||
EmailNotification: &newreleases.EmailNotificationHourly, | ||
} | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Print(p.ID) | ||
} | ||
``` | ||
|
||
List projects with pagination: | ||
|
||
```go | ||
func AllProjects(ctx context.Context, client *newreleases.Client) (pp []newreleases.Project, err error) { | ||
o := &newreleases.ProjectListOptions{ | ||
Page: 1, | ||
} | ||
for { | ||
projects, lastPage, err := client.Projects.List(ctx, o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pp = append(pp, projects...) | ||
|
||
if o.Page >= lastPage { | ||
break | ||
} | ||
o.Page++ | ||
} | ||
|
||
return pp, nil | ||
} | ||
``` | ||
|
||
## Versioning | ||
|
||
Each version of the client is tagged and the version is updated accordingly. | ||
|
||
This package uses Go modules. | ||
|
||
To see the list of past versions, run `git tag`. | ||
|
||
## Contributing | ||
|
||
We love pull requests! Please see the [contribution guidelines](CONTRIBUTING.md). | ||
|
||
## License | ||
|
||
This library is distributed under the BSD-style license found in the [LICENSE](LICENSE) file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2019, NewReleases Go client 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 newreleases | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// AuthService provides information about API authentication. | ||
type AuthService service | ||
|
||
// AuthKey represents API authentication secret key, with its descriptive name | ||
// and authorized networks. | ||
type AuthKey struct { | ||
Name string `json:"name"` | ||
Secret string `json:"secret"` | ||
AuthorizedNetworks []net.IPNet `json:"authorized_networks"` | ||
} | ||
|
||
// List returns all authentication keys. | ||
func (s *AuthService) List(ctx context.Context) (keys []AuthKey, err error) { | ||
var r authKeysResponse | ||
err = s.client.request(ctx, http.MethodGet, "v1/auth/keys", nil, &r) | ||
return r.AuthKeys(), err | ||
} | ||
|
||
// GetAuthKeys returns a list of all auth keys for an account by authenticating | ||
// with account's email address and a password. This function can be used to get | ||
// the authentication key without providing it explicitly to the client, but | ||
// first asking for already known (to the user) credentials. | ||
func GetAuthKeys(ctx context.Context, email, password string, o *ClientOptions) (keys []AuthKey, err error) { | ||
return newBasicAuthClient(email, password, o).Auth.List(ctx) | ||
} | ||
|
||
type authKeysResponse struct { | ||
Keys []authKey `json:"keys"` | ||
} | ||
|
||
func (r *authKeysResponse) AuthKeys() (ak []AuthKey) { | ||
ak = make([]AuthKey, len(r.Keys)) | ||
for i, k := range r.Keys { | ||
ak[i] = AuthKey{ | ||
Name: k.Name, | ||
Secret: k.Secret, | ||
AuthorizedNetworks: k.authorizedNetworks(), | ||
} | ||
} | ||
return ak | ||
} | ||
|
||
type authKey struct { | ||
Name string `json:"name"` | ||
Secret string `json:"secret"` | ||
AuthorizedNetworks []ipNet `json:"authorized_networks"` | ||
} | ||
|
||
func (k *authKey) authorizedNetworks() (an []net.IPNet) { | ||
an = make([]net.IPNet, len(k.AuthorizedNetworks)) | ||
for i, n := range k.AuthorizedNetworks { | ||
an[i] = net.IPNet(n) | ||
} | ||
return an | ||
} | ||
|
||
type ipNet net.IPNet | ||
|
||
func (n *ipNet) UnmarshalJSON(data []byte) (err error) { | ||
_, nn, err := net.ParseCIDR(strings.Trim(string(data), `"`)) | ||
if err != nil { | ||
return err | ||
} | ||
*n = ipNet(*nn) | ||
return nil | ||
} |
Oops, something went wrong.