coveralls

package module
v0.0.0-...-dbae621 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 4 Imported by: 0

README

go-coveralls-api

Coverage Status GoDoc

Client for Coveralls API written in Go.

Note: the goal is to interact with administrative Coveralls API. To send coverage data, take a look at goveralls project.

Installation

Just follow the usual instructions for Go libraries:

go get github.com/loadsmart/go-coveralls-api

go-coveralls-api uses Go Modules and therefore requires Go 1.11+.

Usage

To get the ID of a repo already configured in Coveralls

import (
    "context"
    "fmt"
    "log"

    "github.com/loadsmart/go-coveralls-api"
)

client := coveralls.NewClient("your-personal-access-token")
repository, err := client.Repositories.Get(context.Background(), "github", "user/repository")
if err != nil {
    log.Fatalf("Error querying Coveralls API: %s\n", err)
}

fmt.Printf("Project has ID %d in Coveralls", repository.ID)

Replace your-personal-access-token with your personal access token (can be found in your Coveralls account page).

License

This work is copyrighted to Loadsmart, Inc. and licensed under MIT. For details see LICENSE file.

Documentation

Overview

Package coveralls provide functions to interact with Coveralls API

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Repositories *RepositoryService // Service to interact with repository-related endpoints
	// contains filtered or unexported fields
}

Client is used to provide a single interface to interact with Coveralls API

func NewClient

func NewClient(t string) *Client

NewClient returns a new Coveralls API Client t is the Coveralls API token

type Repository

type Repository struct {
	ID       int    `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	HasBadge bool   `json:"has_badge,omitempty"`
	Token    string `json:"token,omitempty"`
}

Repository holds information about one specific repository

type RepositoryConfig

type RepositoryConfig struct {
	Service                         string   `json:"service"`                             // Git provider. Options include: github, bitbucket, gitlab, stash, manual
	Name                            string   `json:"name"`                                // Name of the repo. E.g. with Github, this is username/reponame.
	CommentOnPullRequests           bool     `json:"comment_on_pull_requests"`            // Whether comments should be posted on pull requests (defaults to true)
	SendBuildStatus                 bool     `json:"send_build_status"`                   // Whether build status should be sent to the git provider (defaults to true)
	CommitStatusFailThreshold       *float64 `json:"commit_status_fail_threshold"`        // Minimum coverage that must be present on a build for the build to pass (default is null, meaning any decrease is a failure)
	CommitStatusFailChangeThreshold *float64 `json:"commit_status_fail_change_threshold"` // If coverage decreases, the maximum allowed amount of decrease that will be allowed for the build to pass (default is null, meaning that any decrease is a failure)
}

RepositoryConfig represents config settings for a given repository

type RepositoryService

type RepositoryService service

RepositoryService holds information to access repository-related endpoints

func (*RepositoryService) Add

Add a repository to Coveralls

func (*RepositoryService) Get

func (s *RepositoryService) Get(ctx context.Context, svc string, repo string) (*Repository, error)

Get information about a repository already in Coveralls.

Ctx is a context that's propagated to underlying client. You can use it to cancel the request in progress (when the program is terminated, for example).

Svc indicates the service. Any value accepted by Coveralls API can be passed here. Soma valid inputs include 'github', 'bitbucket' or 'manual'.

Repo is the repository name. In GitHub, for example, this is 'organization/repository'; other services could have different formats.

If the request suceeded, it returns a Repository with the information available or an error if there was something wrong.

Example
// Instantiate the client with your _personal access token_
client := NewClient("your-personal-access-token")
// This returns information about a specific repository
repository, err := client.Repositories.Get(context.Background(), "github", "user/repository")
if err != nil {
	log.Fatalf("Error querying Coveralls API: %s\n", err)
}

fmt.Printf("Project has ID %d in Coveralls", repository.ID)
Output:

func (*RepositoryService) Update

Update repository configuration in Coveralls

Jump to

Keyboard shortcuts

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