newreleases

package module
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2022 License: BSD-3-Clause Imports: 13 Imported by: 2

README

NewReleases API v1 Go client

Go GoDoc NewReleases

Package newreleases is a Go client library for accessing the NewReleases v1 API.

You can view the client API docs here: https://godoc.org/newreleases.io/newreleases

You can view NewReleases API docs here: https://newreleases.io/api/v1

Installation

Run go get newreleases.io/newreleases from command line.

Usage

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.

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 latest non-excluded project release
  • Get project release note
  • Get tracked providers
  • Get added Slack Channels
  • Get added Telegram Chats
  • Get added Dissord Channels
  • Get added Hangouts Chat webhooks
  • Get added Microsoft Teams webhooks
  • Get added Mattermost webhooks
  • Get added Rocket.Chat webhooks
  • Get added Matrix Rooms
  • Get added custom Webhooks
  • List tags
  • Get tag
  • Add tag
  • Update tag
  • Delete tag
  • Get auth keys

Examples

To add a new project:

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:

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.

License

This library is distributed under the BSD-style license found in the LICENSE file.

Documentation

Overview

Package newreleases is the NewReleases API v1 client for Go.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized        = errors.New("unauthorized")
	ErrForbidden           = errors.New("forbidden")
	ErrNotFound            = errors.New("not found")
	ErrMethodNotAllowed    = errors.New("method not allowed")
	ErrTooManyRequests     = errors.New("too many requests")
	ErrInternalServerError = errors.New("internal server error")
	ErrMaintenance         = errors.New("maintenance")
)

Errors that are returned by the API.

Functions

func Bool

func Bool(v bool) (p *bool)

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func String added in v1.8.0

func String(v string) (p *string)

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type AuthKey

type AuthKey struct {
	Name               string      `json:"name"`
	Secret             string      `json:"secret"`
	AuthorizedNetworks []net.IPNet `json:"authorized_networks"`
}

AuthKey represents API authentication secret key, with its descriptive name and authorized networks.

func GetAuthKeys

func GetAuthKeys(ctx context.Context, email, password string, o *ClientOptions) (keys []AuthKey, err error)

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.

type AuthService

type AuthService service

AuthService provides information about API authentication.

func (*AuthService) List

func (s *AuthService) List(ctx context.Context) (keys []AuthKey, err error)

List returns all authentication keys.

type BadRequestError

type BadRequestError struct {
	// contains filtered or unexported fields
}

BadRequestError holds list of errors from http response that represent invalid data submitted by the user.

func NewBadRequestError

func NewBadRequestError(errors ...string) (err *BadRequestError)

NewBadRequestError constructs a new BadRequestError with provided errors.

func (*BadRequestError) Error

func (e *BadRequestError) Error() (s string)

func (*BadRequestError) Errors

func (e *BadRequestError) Errors() (errs []string)

Errors returns a list of error messages.

type Client

type Client struct {

	// Services that API provides.
	Auth                   *AuthService
	Providers              *ProvidersService
	Projects               *ProjectsService
	Releases               *ReleasesService
	SlackChannels          *SlackChannelsService
	TelegramChats          *TelegramChatsService
	DiscordChannels        *DiscordChannelsService
	HangoutsChatWebhooks   *HangoutsChatWebhooksService
	MicrosoftTeamsWebhooks *MicrosoftTeamsWebhooksService
	MattermostWebhooks     *MattermostWebhooksService
	RocketchatWebhooks     *RocketchatWebhooksService
	MatrixRooms            *MatrixRoomsService
	Webhooks               *WebhooksService
	Tags                   *TagsService
	// contains filtered or unexported fields
}

Client manages communication with the NewReleases API.

func NewClient

func NewClient(key string, o *ClientOptions) (c *Client)

NewClient constructs a new Client that uses API key authentication.

func (*Client) Rate

func (c *Client) Rate() (r Rate)

Rate returns the current request rate limit information.

type ClientOptions

type ClientOptions struct {
	HTTPClient *http.Client
	BaseURL    *url.URL
}

ClientOptions holds optional parameters for the Client.

type DiscordChannel added in v1.3.0

type DiscordChannel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

DiscordChannel holds information about a Discord Channel that is connected to the account.

type DiscordChannelsService added in v1.3.0

type DiscordChannelsService service

DiscordChannelsService provides information about Discord notifications.

func (*DiscordChannelsService) List added in v1.3.0

func (s *DiscordChannelsService) List(ctx context.Context) (channels []DiscordChannel, err error)

List returns all connected Discord Channels.

type EmailNotification

type EmailNotification string

EmailNotification enumerates available options for email notifications.

var (
	EmailNotificationNone    EmailNotification = "none"
	EmailNotificationInstant EmailNotification = "instant"
	EmailNotificationHourly  EmailNotification = "hourly"
	EmailNotificationDaily   EmailNotification = "daily"
	EmailNotificationWeekly  EmailNotification = "weekly"
	EmailNotificationDefault EmailNotification = "default"
)

Available email notification options.

type Exclusion

type Exclusion struct {
	Value   string `json:"value"`
	Inverse bool   `json:"inverse"`
}

Exclusion holds information about a regular expression used to filter release versions.

type HangoutsChatWebhooksService

type HangoutsChatWebhooksService service

HangoutsChatWebhooksService provides information about Google Hangouts Chat Webhooks notifications.

func (*HangoutsChatWebhooksService) List

func (s *HangoutsChatWebhooksService) List(ctx context.Context) (webhooks []Webhook, err error)

List returns all Google Hangouts Chat webhooks.

type MatrixRoom added in v1.9.0

type MatrixRoom struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	HomeserverURL  string `json:"homeserver_url"`
	InternalRoomID string `json:"internal_room_id"`
}

MatrixRoom holds information about a Slack Channel that is connected to the account.

type MatrixRoomsService added in v1.9.0

type MatrixRoomsService service

MatrixRoomsService provides information about Matrix notifications.

func (*MatrixRoomsService) List added in v1.9.0

func (s *MatrixRoomsService) List(ctx context.Context) (rooms []MatrixRoom, err error)

List returns all Matrix rooms.

type MattermostWebhooksService added in v1.6.0

type MattermostWebhooksService service

MattermostWebhooksService provides information about Mattermost Webhooks notifications.

func (*MattermostWebhooksService) List added in v1.6.0

func (s *MattermostWebhooksService) List(ctx context.Context) (webhooks []Webhook, err error)

List returns all Mattermost webhooks.

type MicrosoftTeamsWebhooksService

type MicrosoftTeamsWebhooksService service

MicrosoftTeamsWebhooksService provides information about Microsoft Teams Webhooks notifications.

func (*MicrosoftTeamsWebhooksService) List

func (s *MicrosoftTeamsWebhooksService) List(ctx context.Context) (webhooks []Webhook, err error)

List returns all Microsoft Teams webhooks.

type Project

type Project struct {
	ID                     string            `json:"id"`
	Name                   string            `json:"name"`
	Provider               string            `json:"provider"`
	URL                    string            `json:"url"`
	EmailNotification      EmailNotification `json:"email_notification,omitempty"`
	SlackIDs               []string          `json:"slack_channels,omitempty"`
	TelegramChatIDs        []string          `json:"telegram_chats,omitempty"`
	DiscordIDs             []string          `json:"discord_channels,omitempty"`
	HangoutsChatWebhookIDs []string          `json:"hangouts_chat_webhooks,omitempty"`
	MSTeamsWebhookIDs      []string          `json:"microsoft_teams_webhooks,omitempty"`
	MattermostWebhookIDs   []string          `json:"mattermost_webhooks,omitempty"`
	RocketchatWebhookIDs   []string          `json:"rocketchat_webhooks,omitempty"`
	MatrixRoomIDs          []string          `json:"matrix_rooms,omitempty"`
	WebhookIDs             []string          `json:"webhooks,omitempty"`
	Exclusions             []Exclusion       `json:"exclude_version_regexp,omitempty"`
	ExcludePrereleases     bool              `json:"exclude_prereleases,omitempty"`
	ExcludeUpdated         bool              `json:"exclude_updated,omitempty"`
	Note                   string            `json:"note,omitempty"`
	TagIDs                 []string          `json:"tags,omitempty"`
}

Project holds information about a tracked project and its configured options.

type ProjectListOptions

type ProjectListOptions struct {
	Page     int
	Order    ProjectListOrder
	Reverse  bool
	Provider string
	TagID    string
}

ProjectListOptions holds information about a project list page.

type ProjectListOrder

type ProjectListOrder string

ProjectListOrder enumerates available project list orders.

var (
	ProjectListOrderUpdated ProjectListOrder = "updated"
	ProjectListOrderAdded   ProjectListOrder = "added"
	ProjectListOrderName    ProjectListOrder = "name"
)

Available project list orders.

type ProjectOptions

type ProjectOptions struct {
	EmailNotification      *EmailNotification `json:"email_notification"`
	SlackIDs               []string           `json:"slack_channels"`
	TelegramChatIDs        []string           `json:"telegram_chats"`
	DiscordIDs             []string           `json:"discord_channels"`
	HangoutsChatWebhookIDs []string           `json:"hangouts_chat_webhooks"`
	MSTeamsWebhookIDs      []string           `json:"microsoft_teams_webhooks"`
	MattermostWebhookIDs   []string           `json:"mattermost_webhooks"`
	MatrixRoomIDs          []string           `json:"matrix_rooms"`
	RocketchatWebhookIDs   []string           `json:"rocketchat_webhooks"`
	WebhookIDs             []string           `json:"webhooks"`
	Exclusions             []Exclusion        `json:"exclude_version_regexp"`
	ExcludePrereleases     *bool              `json:"exclude_prereleases"`
	ExcludeUpdated         *bool              `json:"exclude_updated"`
	Note                   *string            `json:"note"`
	TagIDs                 []string           `json:"tags"`
}

ProjectOptions holds information for setting options for a specific project. If any of the fields have nil value, the option is not set by Add method or changed by UpdateByID or UpdateByName methods. When using update methods, removing all elements must be done by setting an initialized slice, not a nil slice. For boolean pointer methods, there is a convenient functions Bool and String that return boolean pointer by passing a regular value.

type ProjectsService

type ProjectsService service

ProjectsService provides information and methods to manage tracked projects.

func (*ProjectsService) Add

func (s *ProjectsService) Add(ctx context.Context, provider, name string, o *ProjectOptions) (project *Project, err error)

Add adds a new project to be tracked.

func (*ProjectsService) DeleteByID

func (s *ProjectsService) DeleteByID(ctx context.Context, id string) (err error)

DeleteByID removes a project referenced by its ID.

func (*ProjectsService) DeleteByName

func (s *ProjectsService) DeleteByName(ctx context.Context, provider, name string) (err error)

DeleteByName removes a project referenced by its provider and name.

func (*ProjectsService) GetByID

func (s *ProjectsService) GetByID(ctx context.Context, id string) (project *Project, err error)

GetByID returns a specific project referenced by its ID.

func (*ProjectsService) GetByName

func (s *ProjectsService) GetByName(ctx context.Context, provider, name string) (project *Project, err error)

GetByName returns a specific project referenced by its provider and name.

func (*ProjectsService) List

func (s *ProjectsService) List(ctx context.Context, o ProjectListOptions) (projects []Project, lastPage int, err error)

List returns a paginated list of tracked projects and the number of the last available page.

func (*ProjectsService) Search

func (s *ProjectsService) Search(ctx context.Context, query, provider string) (projects []Project, err error)

Search performs a search with provided query on names of all tracked projects. Provider argument is optional and all projects are searched if it is a blank string.

func (*ProjectsService) UpdateByID

func (s *ProjectsService) UpdateByID(ctx context.Context, id string, o *ProjectOptions) (project *Project, err error)

UpdateByID changes project options referenced by its ID.

func (*ProjectsService) UpdateByName

func (s *ProjectsService) UpdateByName(ctx context.Context, provider, name string, o *ProjectOptions) (project *Project, err error)

UpdateByName changes project options referenced by its provider and name.

type ProvidersService

type ProvidersService service

ProvidersService provides information about supported project providers and providers for projects that are added for tracking.

func (*ProvidersService) List

func (s *ProvidersService) List(ctx context.Context) (providers []string, err error)

List returns all supported project providers.

func (*ProvidersService) ListAdded

func (s *ProvidersService) ListAdded(ctx context.Context) (providers []string, err error)

ListAdded returns poviders for projects that are added for tracking.

type Rate

type Rate struct {
	Limit     int       // The maximum number of requests that the user is permitted to make per hour.
	Remaining int       // The number of requests remaining in the current rate limit window.
	Reset     time.Time // Seconds until current rate limit window will reset to the maximal value.
	Retry     time.Time // Seconds until new requests are permitted when limit is reached.
}

Rate contains the request rate limit information.

func (Rate) String

func (r Rate) String() (s string)

type Release

type Release struct {
	Version      string    `json:"version"`
	Date         time.Time `json:"date"`
	CVE          []string  `json:"cve,omitempty"`
	IsPrerelease bool      `json:"is_prerelease,omitempty"`
	IsUpdated    bool      `json:"is_updated,omitempty"`
	IsExcluded   bool      `json:"is_excluded,omitempty"`
	HasNote      bool      `json:"has_note,omitempty"`
}

Release holds information about a specific released version.

type ReleaseNote

type ReleaseNote struct {
	Title   string `json:"title,omitempty"`
	Message string `json:"message,omitempty"`
	URL     string `json:"url,omitempty"`
}

ReleaseNote holds information about an additional note for a specific version.

type ReleasesService

type ReleasesService service

ReleasesService provides information about releases for every project that is tracked.

func (*ReleasesService) GetByProjectID

func (s *ReleasesService) GetByProjectID(ctx context.Context, projectID, version string) (release *Release, err error)

GetByProjectID returns a specific version release for a project referenced by its ID.

func (*ReleasesService) GetByProjectName

func (s *ReleasesService) GetByProjectName(ctx context.Context, provider, projectName, version string) (release *Release, err error)

GetByProjectName returns a specific version release for a project referenced by its provider and name.

func (*ReleasesService) GetLatestByProjectID added in v1.10.0

func (s *ReleasesService) GetLatestByProjectID(ctx context.Context, projectID string) (release *Release, err error)

GetLatestByProjectID returns the latest non-excluded version release for a project referenced by its ID.

func (*ReleasesService) GetLatestByProjectName added in v1.10.0

func (s *ReleasesService) GetLatestByProjectName(ctx context.Context, provider, projectName string) (release *Release, err error)

GetLatestByProjectName returns the latest non-excluded version release for a project referenced by its provider and name.

func (*ReleasesService) GetNoteByProjectID

func (s *ReleasesService) GetNoteByProjectID(ctx context.Context, projectID string, version string) (release *ReleaseNote, err error)

GetNoteByProjectID returns a specific release note for a project referenced by its ID.

func (*ReleasesService) GetNoteByProjectName

func (s *ReleasesService) GetNoteByProjectName(ctx context.Context, provider, projectName string, version string) (release *ReleaseNote, err error)

GetNoteByProjectName returns a specific release note for a project referenced by its provider and name.

func (*ReleasesService) ListByProjectID

func (s *ReleasesService) ListByProjectID(ctx context.Context, projectID string, page int) (releases []Release, lastPage int, err error)

ListByProjectID returns a paginated list of project releases and the number of the last page. The project is referenced by its ID.

func (*ReleasesService) ListByProjectName

func (s *ReleasesService) ListByProjectName(ctx context.Context, provider, projectName string, page int) (releases []Release, lastPage int, err error)

ListByProjectName returns a paginated list of project releases and the number of the last page. The project is referenced by its provider and name.

type RocketchatWebhooksService added in v1.7.0

type RocketchatWebhooksService service

RocketchatWebhooksService provides information about Rocket.Chat Webhooks notifications.

func (*RocketchatWebhooksService) List added in v1.7.0

func (s *RocketchatWebhooksService) List(ctx context.Context) (webhooks []Webhook, err error)

List returns all Rocket.Chat webhooks.

type SlackChannel

type SlackChannel struct {
	ID       string `json:"id"`
	Channel  string `json:"channel"`
	TeamName string `json:"team_name"`
}

SlackChannel holds information about a Slack Channel that is connected to the account.

type SlackChannelsService

type SlackChannelsService service

SlackChannelsService provides information about Slack notifications.

func (*SlackChannelsService) List

func (s *SlackChannelsService) List(ctx context.Context) (channels []SlackChannel, err error)

List returns all connected Slack Channels.

type Tag added in v1.8.0

type Tag struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Tag holds the information about tag ID and its descriptive name.

type TagsService added in v1.8.0

type TagsService service

TagsService provides information about project Tags.

func (*TagsService) Add added in v1.8.0

func (s *TagsService) Add(ctx context.Context, name string) (tag *Tag, err error)

Add adds a new tag.

func (*TagsService) Delete added in v1.8.0

func (s *TagsService) Delete(ctx context.Context, id string) error

Delete removes the tag by its ID.

func (*TagsService) Get added in v1.8.0

func (s *TagsService) Get(ctx context.Context, id string) (tag *Tag, err error)

Get returns the tag by its ID.

func (*TagsService) List added in v1.8.0

func (s *TagsService) List(ctx context.Context) (tags []Tag, err error)

List returns all tags.

func (*TagsService) Update added in v1.8.0

func (s *TagsService) Update(ctx context.Context, id, name string) (tag *Tag, err error)

Update changes the name of the tag referenced by the ID.

type TelegramChat added in v1.1.0

type TelegramChat struct {
	ID   string `json:"id"`
	Type string `json:"type"`
	Name string `json:"name"`
}

TelegramChat holds information about a Telegram Chat which receives notifications.

type TelegramChatsService added in v1.1.0

type TelegramChatsService service

TelegramChatsService provides information about Telegram notifications.

func (*TelegramChatsService) List added in v1.1.0

func (s *TelegramChatsService) List(ctx context.Context) (channels []TelegramChat, err error)

List returns all connected Telegram Chats.

type Webhook

type Webhook struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Webhook holds the information about webhook ID and its descriptive name.

type WebhooksService

type WebhooksService service

WebhooksService provides information about Webhooks notifications.

func (*WebhooksService) List

func (s *WebhooksService) List(ctx context.Context) (webhooks []Webhook, err error)

List returns all webhooks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL