Giter Site home page Giter Site logo

swipswaps / go-scm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambdatest/go-scm

0.0 1.0 0.0 764 KB

Package scm provides a unified interface to multiple source code management systems.

Home Page: https://godoc.org/github.com/drone/go-scm/scm#pkg-examples

License: Other

Go 100.00%

go-scm's Introduction

Go Doc

Package scm provides a unified interface to multiple source code management systems including GitHub, GitHub Enterprise, Bitbucket, Bitbucket Server, Gitea and Gogs.

Getting Started

Create a GitHub client:

package main

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/github"
)

func main() {
	client := github.NewDefault()
}

Create a GitHub Enterprise client:

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/github"
)

func main() {
    client, err := github.New("https://github.company.com/api/v3")
}

Create a Bitbucket client:

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/bitbucket"
)

func main() {
    client, err := bitbucket.New()
}

Create a Bitbucket Server (Stash) client:

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/stash"
)

func main() {
    client, err := stash.New("https://stash.company.com")
}

Create a Gitea client:

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/github"
)

func main() {
    client, err := gitea.New("https://gitea.company.com")
}

Authentication

The scm client does not directly handle authentication. Instead, when creating a new client, provide a http.Client that can handle authentication for you. For convenience, this library includes oauth1 and oauth2 implementations that can be used to authenticate requests.

package main

import (
	"github.com/drone/go-scm/scm"
	"github.com/drone/go-scm/scm/driver/github"
	"github.com/drone/go-scm/scm/driver/transport/oauth2"
)

func main() {
	client := github.NewDefault()

	// provide a custom http.Client with a transport
	// that injects the oauth2 token.
	client.Client := &http.Client{
		Transport: &Transport{
			Source: StaticTokenSource(
				&scm.Token{
					Token: "ecf4c1f9869f59758e679ab54b4",
				},
			),
		},
	}

	// provide a custom http.Client with a transport
	// that injects the private GitLab token through
	// the PRIVATE_TOKEN header variable.
	client.Client := &http.Client{
		Transport: &PrivateToken{
			Token: "ecf4c1f9869f59758e679ab54b4",
		},
	}
}

go-scm's People

Contributors

bradrydzewski avatar christianruhstaller avatar cirnot avatar daniel-meister avatar jezhodges avatar jkdev81 avatar jlehtimaki avatar lunny avatar marcotuna avatar nathan-fps avatar ogarcia avatar pgaskin avatar rishabh-arya95 avatar shubhag avatar takirala avatar tboerger avatar techknowlogick avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.