Fix merge conflict
commit
733e13c6f0
28
CHANGELOG.md
28
CHANGELOG.md
|
@ -1,5 +1,33 @@
|
||||||
# Minikube Release Notes
|
# Minikube Release Notes
|
||||||
|
|
||||||
|
# Version 0.32.0 - 12/21/2018
|
||||||
|
|
||||||
|
* Make Kubernetes v1.12.4 the default [#3482](https://github.com/kubernetes/minikube/pull/3482)
|
||||||
|
* Update kubeadm restart commands to support v1.13.x [#3483](https://github.com/kubernetes/minikube/pull/3483)
|
||||||
|
* Make "stop" retry on failure. [#3479](https://github.com/kubernetes/minikube/pull/3479)
|
||||||
|
* VirtualBox time cleanup: sync on boot, don't run timesyncd [#3476](https://github.com/kubernetes/minikube/pull/3476)
|
||||||
|
* Stream cmd output to tests when -v is enabled, and stream SSH output to logs [#3475](https://github.com/kubernetes/minikube/pull/3475)
|
||||||
|
* Document None driver docker compatibility [#3367](https://github.com/kubernetes/minikube/pull/3367)
|
||||||
|
* Enable host DNS resolution in virtualbox driver by default [#3453](https://github.com/kubernetes/minikube/pull/3453)
|
||||||
|
* Fix CRI socket in Kubernetes >= 1.12.0 kubeadmin config [#3452](https://github.com/kubernetes/minikube/pull/3452)
|
||||||
|
* Bump dashboard version to v1.10.1 [#3466](https://github.com/kubernetes/minikube/pull/3466)
|
||||||
|
* Hide KVM signature when using GPU passthrough to support more GPU models [#3459](https://github.com/kubernetes/minikube/pull/3459)
|
||||||
|
* Allow ServiceCIDR to be configured via 'service-cluster-ip-range' flag. [#3463](https://github.com/kubernetes/minikube/pull/3463)
|
||||||
|
* Save old cluster config in memory before overwriting [#3450](https://github.com/kubernetes/minikube/pull/3450)
|
||||||
|
* Change restart policy on gvisor pod [#3445](https://github.com/kubernetes/minikube/pull/3445)
|
||||||
|
|
||||||
|
Shout-out to the amazing members of the minikube community who made this release possible:
|
||||||
|
|
||||||
|
- Alasdair Tran
|
||||||
|
- Balint Pato
|
||||||
|
- Charles-Henri de Boysson
|
||||||
|
- Chris Eason
|
||||||
|
- Cory Locklear
|
||||||
|
- Jeffrey Sica
|
||||||
|
- JoeWrightss
|
||||||
|
- RA489
|
||||||
|
- Thomas Strömberg
|
||||||
|
|
||||||
# Version 0.31.0 - 12/08/2018
|
# Version 0.31.0 - 12/08/2018
|
||||||
|
|
||||||
* Enable gvisor addon in minikube [#3399](https://github.com/kubernetes/minikube/pull/3399)
|
* Enable gvisor addon in minikube [#3399](https://github.com/kubernetes/minikube/pull/3399)
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
]
|
]
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "19035310d4ba1b58056aae427ea669d1db5fc618"
|
revision = "19035310d4ba1b58056aae427ea669d1db5fc618"
|
||||||
|
source = "github.com/machine-drivers/machine"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:364ef519880c6024191ac7660244e5478b193489bb35755f843627cc86cfb411"
|
digest = "1:364ef519880c6024191ac7660244e5478b193489bb35755f843627cc86cfb411"
|
||||||
|
@ -176,6 +177,22 @@
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "3165313d6d3f973ec0b0ed3ec5a63b520e065d40"
|
revision = "3165313d6d3f973ec0b0ed3ec5a63b520e065d40"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:63ede27834b468648817fb80cfb95d40abfc61341f89cb7a0d6779b6aa955425"
|
||||||
|
name = "github.com/google/go-github"
|
||||||
|
packages = ["github"]
|
||||||
|
pruneopts = "NUT"
|
||||||
|
revision = "a5cb647b1fac8ba77e1cf25af2f9526658ab63e3"
|
||||||
|
version = "v21.0.0"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:a63cff6b5d8b95638bfe300385d93b2a6d9d687734b863da8e09dc834510a690"
|
||||||
|
name = "github.com/google/go-querystring"
|
||||||
|
packages = ["query"]
|
||||||
|
pruneopts = "NUT"
|
||||||
|
revision = "44c6ddd0a2342c386950e880b658017258da92fc"
|
||||||
|
version = "v1.0.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:f9425215dccf1c63f659ec781ca46bc81804341821d0cd8d2459c5b58f8bd067"
|
digest = "1:f9425215dccf1c63f659ec781ca46bc81804341821d0cd8d2459c5b58f8bd067"
|
||||||
name = "github.com/google/gofuzz"
|
name = "github.com/google/gofuzz"
|
||||||
|
@ -307,6 +324,14 @@
|
||||||
revision = "5ba8227244c30438609adcec6ea84dc1e688dfbd"
|
revision = "5ba8227244c30438609adcec6ea84dc1e688dfbd"
|
||||||
version = "v3.4.0"
|
version = "v3.4.0"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:c436d61d2f9af426241770422ef9f7a21edc7898963caa88c997c3f968770045"
|
||||||
|
name = "github.com/machine-drivers/docker-machine-driver-vmware"
|
||||||
|
packages = ["pkg/drivers/vmware/config"]
|
||||||
|
pruneopts = "NUT"
|
||||||
|
revision = "cd992887ede19ae63e030c63dda5593f19ed569c"
|
||||||
|
version = "v0.1.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:1745a9a20b54531ca6d6db617f47ac6d367e5d004c7a44ba39149928bca8caff"
|
digest = "1:1745a9a20b54531ca6d6db617f47ac6d367e5d004c7a44ba39149928bca8caff"
|
||||||
name = "github.com/magiconair/properties"
|
name = "github.com/magiconair/properties"
|
||||||
|
@ -568,10 +593,11 @@
|
||||||
revision = "81e90905daefcd6fd217b62423c0908922eadb30"
|
revision = "81e90905daefcd6fd217b62423c0908922eadb30"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:866122db0f3007816dccd5b50ba0b3ae593bdadb81f725a17b95c8c6953c5cb7"
|
digest = "1:546efc585d0b3b4ef026faa94ae2d3211c1744d517841a27c83905e18fd0828d"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = [
|
||||||
"context",
|
"context",
|
||||||
|
"context/ctxhttp",
|
||||||
"http2",
|
"http2",
|
||||||
"http2/hpack",
|
"http2/hpack",
|
||||||
"idna",
|
"idna",
|
||||||
|
@ -580,6 +606,17 @@
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "1c05540f6879653db88113bc4a2b70aec4bd491f"
|
revision = "1c05540f6879653db88113bc4a2b70aec4bd491f"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:9822dde4525c2bc0130c4b8d209cb08b3ab68d4865972b20fe213fc2f732d9db"
|
||||||
|
name = "golang.org/x/oauth2"
|
||||||
|
packages = [
|
||||||
|
".",
|
||||||
|
"internal",
|
||||||
|
]
|
||||||
|
pruneopts = "NUT"
|
||||||
|
revision = "5dab4167f31cbd76b407f1486c86b40748bc5073"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:39485a034b89a9f2892b9c0cc24e2330e1c9981794c35281c2febfcc55b90a34"
|
digest = "1:39485a034b89a9f2892b9c0cc24e2330e1c9981794c35281c2febfcc55b90a34"
|
||||||
name = "golang.org/x/sync"
|
name = "golang.org/x/sync"
|
||||||
|
@ -625,6 +662,22 @@
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "f51c12702a4d776e4c1fa9b0fabab841babae631"
|
revision = "f51c12702a4d776e4c1fa9b0fabab841babae631"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:34c10243da5972105edd1b4b883e2bd918fbb3f73fbe14d6af6929e547173494"
|
||||||
|
name = "google.golang.org/appengine"
|
||||||
|
packages = [
|
||||||
|
"internal",
|
||||||
|
"internal/base",
|
||||||
|
"internal/datastore",
|
||||||
|
"internal/log",
|
||||||
|
"internal/remote_api",
|
||||||
|
"internal/urlfetch",
|
||||||
|
"urlfetch",
|
||||||
|
]
|
||||||
|
pruneopts = "NUT"
|
||||||
|
revision = "e9657d882bb81064595ca3b56cbe2546bbabf7b1"
|
||||||
|
version = "v1.4.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:f8dc0e20a5e1cbc728a21d00e0aef61b6101dda57e45ea1ed1ab148355864e5d"
|
digest = "1:f8dc0e20a5e1cbc728a21d00e0aef61b6101dda57e45ea1ed1ab148355864e5d"
|
||||||
name = "gopkg.in/cheggaaa/pb.v1"
|
name = "gopkg.in/cheggaaa/pb.v1"
|
||||||
|
@ -876,10 +929,12 @@
|
||||||
"github.com/google/go-containerregistry/pkg/name",
|
"github.com/google/go-containerregistry/pkg/name",
|
||||||
"github.com/google/go-containerregistry/pkg/v1/remote",
|
"github.com/google/go-containerregistry/pkg/v1/remote",
|
||||||
"github.com/google/go-containerregistry/pkg/v1/tarball",
|
"github.com/google/go-containerregistry/pkg/v1/tarball",
|
||||||
|
"github.com/google/go-github/github",
|
||||||
"github.com/hooklift/iso9660",
|
"github.com/hooklift/iso9660",
|
||||||
"github.com/jimmidyson/go-download",
|
"github.com/jimmidyson/go-download",
|
||||||
"github.com/johanneswuerbach/nfsexports",
|
"github.com/johanneswuerbach/nfsexports",
|
||||||
"github.com/libvirt/libvirt-go",
|
"github.com/libvirt/libvirt-go",
|
||||||
|
"github.com/machine-drivers/docker-machine-driver-vmware/pkg/drivers/vmware/config",
|
||||||
"github.com/moby/hyperkit/go",
|
"github.com/moby/hyperkit/go",
|
||||||
"github.com/olekukonko/tablewriter",
|
"github.com/olekukonko/tablewriter",
|
||||||
"github.com/pborman/uuid",
|
"github.com/pborman/uuid",
|
||||||
|
@ -887,6 +942,7 @@
|
||||||
"github.com/pkg/errors",
|
"github.com/pkg/errors",
|
||||||
"github.com/pkg/profile",
|
"github.com/pkg/profile",
|
||||||
"github.com/r2d4/external-storage/lib/controller",
|
"github.com/r2d4/external-storage/lib/controller",
|
||||||
|
"github.com/sirupsen/logrus",
|
||||||
"github.com/spf13/cobra",
|
"github.com/spf13/cobra",
|
||||||
"github.com/spf13/cobra/doc",
|
"github.com/spf13/cobra/doc",
|
||||||
"github.com/spf13/pflag",
|
"github.com/spf13/pflag",
|
||||||
|
@ -895,6 +951,7 @@
|
||||||
"github.com/zchee/go-vmnet",
|
"github.com/zchee/go-vmnet",
|
||||||
"golang.org/x/crypto/ssh",
|
"golang.org/x/crypto/ssh",
|
||||||
"golang.org/x/crypto/ssh/terminal",
|
"golang.org/x/crypto/ssh/terminal",
|
||||||
|
"golang.org/x/oauth2",
|
||||||
"golang.org/x/sync/errgroup",
|
"golang.org/x/sync/errgroup",
|
||||||
"golang.org/x/sync/syncmap",
|
"golang.org/x/sync/syncmap",
|
||||||
"golang.org/x/sys/windows/registry",
|
"golang.org/x/sys/windows/registry",
|
||||||
|
@ -925,6 +982,7 @@
|
||||||
"k8s.io/client-go/util/homedir",
|
"k8s.io/client-go/util/homedir",
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants",
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants",
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/features",
|
"k8s.io/kubernetes/cmd/kubeadm/app/features",
|
||||||
|
"k8s.io/kubernetes/pkg/apis/core",
|
||||||
]
|
]
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
# Bump these on release
|
# Bump these on release
|
||||||
VERSION_MAJOR ?= 0
|
VERSION_MAJOR ?= 0
|
||||||
VERSION_MINOR ?= 31
|
VERSION_MINOR ?= 32
|
||||||
VERSION_BUILD ?= 0
|
VERSION_BUILD ?= 0
|
||||||
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
|
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
|
||||||
DEB_VERSION ?= $(VERSION_MAJOR).$(VERSION_MINOR)-$(VERSION_BUILD)
|
DEB_VERSION ?= $(VERSION_MAJOR).$(VERSION_MINOR)-$(VERSION_BUILD)
|
||||||
|
@ -27,7 +27,7 @@ HYPERKIT_BUILD_IMAGE ?= karalabe/xgo-1.10.x
|
||||||
BUILD_IMAGE ?= k8s.gcr.io/kube-cross:v1.11.1-1
|
BUILD_IMAGE ?= k8s.gcr.io/kube-cross:v1.11.1-1
|
||||||
ISO_BUILD_IMAGE ?= $(REGISTRY)/buildroot-image
|
ISO_BUILD_IMAGE ?= $(REGISTRY)/buildroot-image
|
||||||
|
|
||||||
ISO_VERSION ?= v0.31.0
|
ISO_VERSION ?= v0.32.0
|
||||||
ISO_BUCKET ?= minikube/iso
|
ISO_BUCKET ?= minikube/iso
|
||||||
|
|
||||||
MINIKUBE_VERSION ?= $(ISO_VERSION)
|
MINIKUBE_VERSION ?= $(ISO_VERSION)
|
||||||
|
@ -62,7 +62,7 @@ HYPERKIT_FILES := ./cmd/drivers/hyperkit
|
||||||
STORAGE_PROVISIONER_FILES := ./cmd/storage-provisioner
|
STORAGE_PROVISIONER_FILES := ./cmd/storage-provisioner
|
||||||
KVM_DRIVER_FILES := ./cmd/drivers/kvm/
|
KVM_DRIVER_FILES := ./cmd/drivers/kvm/
|
||||||
|
|
||||||
MINIKUBE_TEST_FILES := ./...
|
MINIKUBE_TEST_FILES := ./cmd/... ./pkg/...
|
||||||
|
|
||||||
MINIKUBE_BUILD_TAGS := container_image_ostree_stub containers_image_openpgp
|
MINIKUBE_BUILD_TAGS := container_image_ostree_stub containers_image_openpgp
|
||||||
MINIKUBE_INTEGRATION_BUILD_TAGS := integration $(MINIKUBE_BUILD_TAGS)
|
MINIKUBE_INTEGRATION_BUILD_TAGS := integration $(MINIKUBE_BUILD_TAGS)
|
||||||
|
@ -94,7 +94,7 @@ out/minikube-windows-amd64.exe: out/minikube-windows-amd64
|
||||||
cp out/minikube-windows-amd64 out/minikube-windows-amd64.exe
|
cp out/minikube-windows-amd64 out/minikube-windows-amd64.exe
|
||||||
|
|
||||||
out/minikube.d: pkg/minikube/assets/assets.go
|
out/minikube.d: pkg/minikube/assets/assets.go
|
||||||
$(MAKEDEPEND) out/minikube-$(GOOS)-$(GOARCH) $(ORG) $(MINIKUBEFILES) $^ > $@
|
$(MAKEDEPEND) out/minikube-$(GOOS)-$(GOARCH) $(ORG) $^ $(MINIKUBEFILES) > $@
|
||||||
|
|
||||||
-include out/minikube.d
|
-include out/minikube.d
|
||||||
out/minikube-%-$(GOARCH): pkg/minikube/assets/assets.go
|
out/minikube-%-$(GOARCH): pkg/minikube/assets/assets.go
|
||||||
|
@ -189,7 +189,7 @@ integration-versioned: out/minikube
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
out/test.d: pkg/minikube/assets/assets.go
|
out/test.d: pkg/minikube/assets/assets.go
|
||||||
$(MAKEDEPEND) -t test $(ORG) $(MINIKUBE_TEST_FILES) $^ > $@
|
$(MAKEDEPEND) -t test $(ORG) $^ $(MINIKUBE_TEST_FILES) > $@
|
||||||
|
|
||||||
-include out/test.d
|
-include out/test.d
|
||||||
test:
|
test:
|
||||||
|
@ -263,7 +263,7 @@ out/minikube-installer.exe: out/minikube-windows-amd64.exe
|
||||||
rm -rf out/windows_tmp
|
rm -rf out/windows_tmp
|
||||||
|
|
||||||
out/docker-machine-driver-hyperkit.d:
|
out/docker-machine-driver-hyperkit.d:
|
||||||
$(MAKEDEPEND) out/docker-machine-driver-hyperkit $(ORG) $(HYPERKIT_FILES) $^ > $@
|
$(MAKEDEPEND) out/docker-machine-driver-hyperkit $(ORG) $^ $(HYPERKIT_FILES) > $@
|
||||||
|
|
||||||
-include out/docker-machine-driver-hyperkit.d
|
-include out/docker-machine-driver-hyperkit.d
|
||||||
out/docker-machine-driver-hyperkit:
|
out/docker-machine-driver-hyperkit:
|
||||||
|
@ -290,7 +290,7 @@ $(ISO_BUILD_IMAGE): deploy/iso/minikube-iso/Dockerfile
|
||||||
@echo "$(@) successfully built"
|
@echo "$(@) successfully built"
|
||||||
|
|
||||||
out/storage-provisioner.d:
|
out/storage-provisioner.d:
|
||||||
$(MAKEDEPEND) out/storage-provisioner $(ORG) $(STORAGE_PROVISIONER_FILES) $^ > $@
|
$(MAKEDEPEND) out/storage-provisioner $(ORG) $^ $(STORAGE_PROVISIONER_FILES) > $@
|
||||||
|
|
||||||
-include out/storage-provisioner.d
|
-include out/storage-provisioner.d
|
||||||
out/storage-provisioner:
|
out/storage-provisioner:
|
||||||
|
@ -327,7 +327,7 @@ release-minikube: out/minikube checksum
|
||||||
gsutil cp out/minikube-$(GOOS)-$(GOARCH).sha256 $(MINIKUBE_UPLOAD_LOCATION)/$(MINIKUBE_VERSION)/minikube-$(GOOS)-$(GOARCH).sha256
|
gsutil cp out/minikube-$(GOOS)-$(GOARCH).sha256 $(MINIKUBE_UPLOAD_LOCATION)/$(MINIKUBE_VERSION)/minikube-$(GOOS)-$(GOARCH).sha256
|
||||||
|
|
||||||
out/docker-machine-driver-kvm2.d:
|
out/docker-machine-driver-kvm2.d:
|
||||||
$(MAKEDEPEND) out/docker-machine-driver-kvm2 $(ORG) $(KVM_DRIVER_FILES) $^ > $@
|
$(MAKEDEPEND) out/docker-machine-driver-kvm2 $(ORG) $^ $(KVM_DRIVER_FILES) > $@
|
||||||
|
|
||||||
-include out/docker-machine-driver-kvm2.d
|
-include out/docker-machine-driver-kvm2.d
|
||||||
out/docker-machine-driver-kvm2:
|
out/docker-machine-driver-kvm2:
|
||||||
|
|
|
@ -144,7 +144,7 @@ var settings = []Setting{
|
||||||
name: "default-storageclass",
|
name: "default-storageclass",
|
||||||
set: SetBool,
|
set: SetBool,
|
||||||
validations: []setFn{IsValidAddon},
|
validations: []setFn{IsValidAddon},
|
||||||
callbacks: []setFn{EnableOrDisableAddon},
|
callbacks: []setFn{EnableOrDisableStorageClasses},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "heapster",
|
name: "heapster",
|
||||||
|
@ -186,7 +186,7 @@ var settings = []Setting{
|
||||||
name: "default-storageclass",
|
name: "default-storageclass",
|
||||||
set: SetBool,
|
set: SetBool,
|
||||||
validations: []setFn{IsValidAddon},
|
validations: []setFn{IsValidAddon},
|
||||||
callbacks: []setFn{EnableOrDisableDefaultStorageClass},
|
callbacks: []setFn{EnableOrDisableStorageClasses},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "storage-provisioner",
|
name: "storage-provisioner",
|
||||||
|
@ -194,6 +194,12 @@ var settings = []Setting{
|
||||||
validations: []setFn{IsValidAddon},
|
validations: []setFn{IsValidAddon},
|
||||||
callbacks: []setFn{EnableOrDisableAddon},
|
callbacks: []setFn{EnableOrDisableAddon},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "storage-provisioner-gluster",
|
||||||
|
set: SetBool,
|
||||||
|
validations: []setFn{IsValidAddon},
|
||||||
|
callbacks: []setFn{EnableOrDisableStorageClasses},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "metrics-server",
|
name: "metrics-server",
|
||||||
set: SetBool,
|
set: SetBool,
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/minikube/pkg/minikube/assets"
|
"k8s.io/minikube/pkg/minikube/assets"
|
||||||
"k8s.io/minikube/pkg/minikube/cluster"
|
"k8s.io/minikube/pkg/minikube/cluster"
|
||||||
"k8s.io/minikube/pkg/minikube/config"
|
"k8s.io/minikube/pkg/minikube/config"
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
"k8s.io/minikube/pkg/minikube/machine"
|
"k8s.io/minikube/pkg/minikube/machine"
|
||||||
"k8s.io/minikube/pkg/minikube/storageclass"
|
"k8s.io/minikube/pkg/minikube/storageclass"
|
||||||
)
|
)
|
||||||
|
@ -138,18 +139,30 @@ func EnableOrDisableAddon(name string, val string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnableOrDisableDefaultStorageClass(name, val string) error {
|
func EnableOrDisableStorageClasses(name, val string) error {
|
||||||
enable, err := strconv.ParseBool(val)
|
enable, err := strconv.ParseBool(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Error parsing boolean")
|
return errors.Wrap(err, "Error parsing boolean")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special logic to disable the default storage class
|
class := constants.DefaultStorageClassProvisioner
|
||||||
if !enable {
|
if name == "storage-provisioner-gluster" {
|
||||||
err := storageclass.DisableDefaultStorageClass()
|
class = "glusterfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
if enable {
|
||||||
|
// Only StorageClass for 'name' should be marked as default
|
||||||
|
err := storageclass.SetDefaultStorageClass(class)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Error disabling default storage class")
|
return errors.Wrapf(err, "Error making %s the default storage class", class)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Unset the StorageClass as default
|
||||||
|
err := storageclass.DisableDefaultStorageClass(class)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Error disabling %s as the default storage class", class)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EnableOrDisableAddon(name, val)
|
return EnableOrDisableAddon(name, val)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,11 @@ import (
|
||||||
"github.com/pkg/browser"
|
"github.com/pkg/browser"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
configcmd "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||||
"k8s.io/minikube/pkg/minikube/cluster"
|
"k8s.io/minikube/pkg/minikube/cluster"
|
||||||
"k8s.io/minikube/pkg/minikube/config"
|
"k8s.io/minikube/pkg/minikube/config"
|
||||||
"k8s.io/minikube/pkg/minikube/machine"
|
"k8s.io/minikube/pkg/minikube/machine"
|
||||||
"k8s.io/minikube/pkg/minikube/service"
|
"k8s.io/minikube/pkg/minikube/service"
|
||||||
|
|
||||||
"k8s.io/minikube/pkg/util"
|
"k8s.io/minikube/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,19 +65,30 @@ var dashboardCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
cluster.EnsureMinikubeRunningOrExit(api, 1)
|
cluster.EnsureMinikubeRunningOrExit(api, 1)
|
||||||
|
|
||||||
|
fmt.Fprintln(os.Stderr, "Enabling dashboard ...")
|
||||||
|
// Enable the dashboard add-on
|
||||||
|
err = configcmd.Set("dashboard", "true")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Unable to enable dashboard: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
ns := "kube-system"
|
ns := "kube-system"
|
||||||
svc := "kubernetes-dashboard"
|
svc := "kubernetes-dashboard"
|
||||||
if err = util.RetryAfter(30, func() error { return service.CheckService(ns, svc) }, 1*time.Second); err != nil {
|
fmt.Fprintln(os.Stderr, "Verifying dashboard health ...")
|
||||||
|
if err = util.RetryAfter(180, func() error { return service.CheckService(ns, svc) }, 1*time.Second); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s is not running: %v\n", ns, svc, err)
|
fmt.Fprintf(os.Stderr, "%s:%s is not running: %v\n", ns, svc, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(os.Stderr, "Launching proxy ...")
|
||||||
p, hostPort, err := kubectlProxy()
|
p, hostPort, err := kubectlProxy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("kubectl proxy: %v", err)
|
glog.Fatalf("kubectl proxy: %v", err)
|
||||||
}
|
}
|
||||||
url := dashboardURL(hostPort, ns, svc)
|
url := dashboardURL(hostPort, ns, svc)
|
||||||
|
|
||||||
|
fmt.Fprintln(os.Stderr, "Verifying proxy health ...")
|
||||||
if err = util.RetryAfter(60, func() error { return checkURL(url) }, 1*time.Second); err != nil {
|
if err = util.RetryAfter(60, func() error { return checkURL(url) }, 1*time.Second); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s is not responding properly: %v\n", url, err)
|
fmt.Fprintf(os.Stderr, "%s is not responding properly: %v\n", url, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -60,12 +60,14 @@ const (
|
||||||
containerRuntime = "container-runtime"
|
containerRuntime = "container-runtime"
|
||||||
criSocket = "cri-socket"
|
criSocket = "cri-socket"
|
||||||
networkPlugin = "network-plugin"
|
networkPlugin = "network-plugin"
|
||||||
|
enableDefaultCNI = "enable-default-cni"
|
||||||
hypervVirtualSwitch = "hyperv-virtual-switch"
|
hypervVirtualSwitch = "hyperv-virtual-switch"
|
||||||
kvmNetwork = "kvm-network"
|
kvmNetwork = "kvm-network"
|
||||||
keepContext = "keep-context"
|
keepContext = "keep-context"
|
||||||
createMount = "mount"
|
createMount = "mount"
|
||||||
featureGates = "feature-gates"
|
featureGates = "feature-gates"
|
||||||
apiServerName = "apiserver-name"
|
apiServerName = "apiserver-name"
|
||||||
|
apiServerPort = "apiserver-port"
|
||||||
dnsDomain = "dns-domain"
|
dnsDomain = "dns-domain"
|
||||||
serviceCIDR = "service-cluster-ip-range"
|
serviceCIDR = "service-cluster-ip-range"
|
||||||
mountString = "mount-string"
|
mountString = "mount-string"
|
||||||
|
@ -97,6 +99,22 @@ assumes you have already installed one of the VM drivers: virtualbox/vmwarefusio
|
||||||
Run: runStart,
|
Run: runStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetContainerRuntime possibly sets the container runtime
|
||||||
|
func SetContainerRuntime(cfg map[string]string, runtime string) map[string]string {
|
||||||
|
switch runtime {
|
||||||
|
case "crio", "cri-o":
|
||||||
|
cfg["runtime-endpoint"] = "unix:///var/run/crio/crio.sock"
|
||||||
|
cfg["image-endpoint"] = "unix:///var/run/crio/crio.sock"
|
||||||
|
case "containerd":
|
||||||
|
cfg["runtime-endpoint"] = "unix:///run/containerd/containerd.sock"
|
||||||
|
cfg["image-endpoint"] = "unix:///run/containerd/containerd.sock"
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
func runStart(cmd *cobra.Command, args []string) {
|
func runStart(cmd *cobra.Command, args []string) {
|
||||||
if glog.V(8) {
|
if glog.V(8) {
|
||||||
glog.Infoln("Viper configuration:")
|
glog.Infoln("Viper configuration:")
|
||||||
|
@ -201,6 +219,20 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.MaybeReportErrorAndExit(err)
|
cmdutil.MaybeReportErrorAndExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// common config (currently none)
|
||||||
|
var cricfg = map[string]string{}
|
||||||
|
selectedContainerRuntime := viper.GetString(containerRuntime)
|
||||||
|
if cricfg := SetContainerRuntime(cricfg, selectedContainerRuntime); cricfg != nil {
|
||||||
|
var command string
|
||||||
|
fmt.Println("Writing crictl config...")
|
||||||
|
if command, err = cmdutil.GetCrictlConfigCommand(cricfg); err == nil {
|
||||||
|
_, err = host.RunSSHCommand(command)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorln("Error writing crictl config: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
selectedKubernetesVersion := viper.GetString(kubernetesVersion)
|
selectedKubernetesVersion := viper.GetString(kubernetesVersion)
|
||||||
if strings.Compare(selectedKubernetesVersion, "") == 0 {
|
if strings.Compare(selectedKubernetesVersion, "") == 0 {
|
||||||
selectedKubernetesVersion = constants.DefaultKubernetesVersion
|
selectedKubernetesVersion = constants.DefaultKubernetesVersion
|
||||||
|
@ -226,18 +258,20 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
kubernetesConfig := cfg.KubernetesConfig{
|
kubernetesConfig := cfg.KubernetesConfig{
|
||||||
KubernetesVersion: selectedKubernetesVersion,
|
KubernetesVersion: selectedKubernetesVersion,
|
||||||
NodeIP: ip,
|
NodeIP: ip,
|
||||||
|
NodePort: viper.GetInt(apiServerPort),
|
||||||
NodeName: constants.DefaultNodeName,
|
NodeName: constants.DefaultNodeName,
|
||||||
APIServerName: viper.GetString(apiServerName),
|
APIServerName: viper.GetString(apiServerName),
|
||||||
APIServerNames: apiServerNames,
|
APIServerNames: apiServerNames,
|
||||||
APIServerIPs: apiServerIPs,
|
APIServerIPs: apiServerIPs,
|
||||||
DNSDomain: viper.GetString(dnsDomain),
|
DNSDomain: viper.GetString(dnsDomain),
|
||||||
FeatureGates: viper.GetString(featureGates),
|
FeatureGates: viper.GetString(featureGates),
|
||||||
ContainerRuntime: viper.GetString(containerRuntime),
|
ContainerRuntime: selectedContainerRuntime,
|
||||||
CRISocket: viper.GetString(criSocket),
|
CRISocket: viper.GetString(criSocket),
|
||||||
NetworkPlugin: viper.GetString(networkPlugin),
|
NetworkPlugin: viper.GetString(networkPlugin),
|
||||||
ServiceCIDR: viper.GetString(serviceCIDR),
|
ServiceCIDR: viper.GetString(serviceCIDR),
|
||||||
ExtraOptions: extraOptions,
|
ExtraOptions: extraOptions,
|
||||||
ShouldLoadCachedImages: shouldCacheImages,
|
ShouldLoadCachedImages: shouldCacheImages,
|
||||||
|
EnableDefaultCNI: viper.GetBool(enableDefaultCNI),
|
||||||
}
|
}
|
||||||
|
|
||||||
k8sBootstrapper, err := GetClusterBootstrapper(api, clusterBootstrapper)
|
k8sBootstrapper, err := GetClusterBootstrapper(api, clusterBootstrapper)
|
||||||
|
@ -281,7 +315,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
glog.Errorln("Error connecting to cluster: ", err)
|
glog.Errorln("Error connecting to cluster: ", err)
|
||||||
}
|
}
|
||||||
kubeHost = strings.Replace(kubeHost, "tcp://", "https://", -1)
|
kubeHost = strings.Replace(kubeHost, "tcp://", "https://", -1)
|
||||||
kubeHost = strings.Replace(kubeHost, ":2376", ":"+strconv.Itoa(pkgutil.APIServerPort), -1)
|
kubeHost = strings.Replace(kubeHost, ":2376", ":"+strconv.Itoa(kubernetesConfig.NodePort), -1)
|
||||||
|
|
||||||
fmt.Println("Setting up kubeconfig...")
|
fmt.Println("Setting up kubeconfig...")
|
||||||
// setup kubeconfig
|
// setup kubeconfig
|
||||||
|
@ -306,8 +340,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
fmt.Println("Stopping extra container runtimes...")
|
fmt.Println("Stopping extra container runtimes...")
|
||||||
|
|
||||||
containerRuntime := viper.GetString(containerRuntime)
|
if config.VMDriver != constants.DriverNone && selectedContainerRuntime != "" {
|
||||||
if config.VMDriver != constants.DriverNone && containerRuntime != "" {
|
|
||||||
if _, err := host.RunSSHCommand("sudo systemctl stop docker"); err == nil {
|
if _, err := host.RunSSHCommand("sudo systemctl stop docker"); err == nil {
|
||||||
_, err = host.RunSSHCommand("sudo systemctl stop docker.socket")
|
_, err = host.RunSSHCommand("sudo systemctl stop docker.socket")
|
||||||
}
|
}
|
||||||
|
@ -315,12 +348,12 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
glog.Errorf("Error stopping docker: %v", err)
|
glog.Errorf("Error stopping docker: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.VMDriver != constants.DriverNone && (containerRuntime != constants.CrioRuntime && containerRuntime != constants.Cri_oRuntime) {
|
if config.VMDriver != constants.DriverNone && (selectedContainerRuntime != constants.CrioRuntime && selectedContainerRuntime != constants.Cri_oRuntime) {
|
||||||
if _, err := host.RunSSHCommand("sudo systemctl stop crio"); err != nil {
|
if _, err := host.RunSSHCommand("sudo systemctl stop crio"); err != nil {
|
||||||
glog.Errorf("Error stopping crio: %v", err)
|
glog.Errorf("Error stopping crio: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.VMDriver != constants.DriverNone && containerRuntime != constants.RktRuntime {
|
if config.VMDriver != constants.DriverNone && selectedContainerRuntime != constants.RktRuntime {
|
||||||
if _, err := host.RunSSHCommand("sudo systemctl stop rkt-api"); err == nil {
|
if _, err := host.RunSSHCommand("sudo systemctl stop rkt-api"); err == nil {
|
||||||
_, err = host.RunSSHCommand("sudo systemctl stop rkt-metadata")
|
_, err = host.RunSSHCommand("sudo systemctl stop rkt-metadata")
|
||||||
}
|
}
|
||||||
|
@ -329,7 +362,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.VMDriver != constants.DriverNone && containerRuntime == constants.ContainerdRuntime {
|
if config.VMDriver != constants.DriverNone && selectedContainerRuntime == constants.ContainerdRuntime {
|
||||||
fmt.Println("Restarting containerd runtime...")
|
fmt.Println("Restarting containerd runtime...")
|
||||||
// restart containerd so that it can install all plugins
|
// restart containerd so that it can install all plugins
|
||||||
if _, err := host.RunSSHCommand("sudo systemctl restart containerd"); err != nil {
|
if _, err := host.RunSSHCommand("sudo systemctl restart containerd"); err != nil {
|
||||||
|
@ -340,7 +373,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
if !exists || config.VMDriver == constants.DriverNone {
|
if !exists || config.VMDriver == constants.DriverNone {
|
||||||
fmt.Println("Starting cluster components...")
|
fmt.Println("Starting cluster components...")
|
||||||
if err := k8sBootstrapper.StartCluster(kubernetesConfig); err != nil {
|
if err := k8sBootstrapper.StartCluster(kubernetesConfig); err != nil {
|
||||||
glog.Errorln("Error starting cluster: ", err)
|
glog.Errorf("Error starting cluster: %v", err)
|
||||||
cmdutil.MaybeReportErrorAndExit(err)
|
cmdutil.MaybeReportErrorAndExit(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -371,15 +404,17 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
st, err := k8sBootstrapper.GetApiServerStatus(net.ParseIP(ip))
|
st, err := k8sBootstrapper.GetApiServerStatus(net.ParseIP(ip))
|
||||||
if err != nil || st != state.Running.String() {
|
if err != nil || st != state.Running.String() {
|
||||||
fmt.Print(".")
|
fmt.Print(".")
|
||||||
return &pkgutil.RetriableError{Err: fmt.Errorf("apiserver unhealthy: %v: %s", err, st)}
|
return &pkgutil.RetriableError{Err: fmt.Errorf("apiserver status=%s err=%v", st, err)}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = pkgutil.RetryAfter(20, aStat, 3*time.Second)
|
|
||||||
|
err = pkgutil.RetryAfter(30, aStat, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: %v", err)
|
fmt.Printf("error: %v", err)
|
||||||
cmdutil.MaybeReportErrorAndExit(err)
|
cmdutil.MaybeReportErrorAndExit(err)
|
||||||
}
|
}
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
// start 9p server mount
|
// start 9p server mount
|
||||||
if viper.GetBool(createMount) {
|
if viper.GetBool(createMount) {
|
||||||
|
@ -470,6 +505,7 @@ func init() {
|
||||||
startCmd.Flags().String(NFSSharesRoot, "/nfsshares", "Where to root the NFS Shares (defaults to /nfsshares, only supported with hyperkit now)")
|
startCmd.Flags().String(NFSSharesRoot, "/nfsshares", "Where to root the NFS Shares (defaults to /nfsshares, only supported with hyperkit now)")
|
||||||
startCmd.Flags().StringArrayVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
|
startCmd.Flags().StringArrayVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
|
||||||
startCmd.Flags().StringArrayVar(&dockerOpt, "docker-opt", nil, "Specify arbitrary flags to pass to the Docker daemon. (format: key=value)")
|
startCmd.Flags().StringArrayVar(&dockerOpt, "docker-opt", nil, "Specify arbitrary flags to pass to the Docker daemon. (format: key=value)")
|
||||||
|
startCmd.Flags().Int(apiServerPort, pkgutil.APIServerPort, "The apiserver listening port")
|
||||||
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||||
startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||||
startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||||
|
@ -481,6 +517,7 @@ func init() {
|
||||||
startCmd.Flags().String(criSocket, "", "The cri socket path to be used")
|
startCmd.Flags().String(criSocket, "", "The cri socket path to be used")
|
||||||
startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3)")
|
startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3)")
|
||||||
startCmd.Flags().String(networkPlugin, "", "The name of the network plugin")
|
startCmd.Flags().String(networkPlugin, "", "The name of the network plugin")
|
||||||
|
startCmd.Flags().Bool(enableDefaultCNI, false, "Enable the default CNI plugin (/etc/cni/net.d/k8s.conf). Used in conjunction with \"--network-plugin=cni\"")
|
||||||
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
|
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
|
||||||
startCmd.Flags().Bool(cacheImages, false, "If true, cache docker images for the current bootstrapper and load them into the machine.")
|
startCmd.Flags().Bool(cacheImages, false, "If true, cache docker images for the current bootstrapper and load them into the machine.")
|
||||||
startCmd.Flags().Var(&extraOptions, "extra-config",
|
startCmd.Flags().Var(&extraOptions, "extra-config",
|
||||||
|
|
|
@ -111,7 +111,7 @@ var statusCmd = &cobra.Command{
|
||||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||||
}
|
}
|
||||||
if ks {
|
if ks {
|
||||||
kubeconfigSt = "Correctly Configured: pointing to minikube-vm at " + ip.String()
|
kubeconfigSt = "Correctly Configured: pointing to minikube-vm at " + ip.String() + "\n"
|
||||||
} else {
|
} else {
|
||||||
kubeconfigSt = "Misconfigured: pointing to stale minikube-vm." +
|
kubeconfigSt = "Misconfigured: pointing to stale minikube-vm." +
|
||||||
"\nTo fix the kubectl context, run minikube update-context"
|
"\nTo fix the kubectl context, run minikube update-context"
|
||||||
|
|
|
@ -27,9 +27,11 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -130,6 +132,7 @@ func MaybeReportErrorAndExit(errToReport error) {
|
||||||
MaybeReportErrorAndExitWithCode(errToReport, 1)
|
MaybeReportErrorAndExitWithCode(errToReport, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaybeReportErrorAndExitWithCode prompts the user if they would like to report a stack trace, and exits.
|
||||||
func MaybeReportErrorAndExitWithCode(errToReport error, returnCode int) {
|
func MaybeReportErrorAndExitWithCode(errToReport error, returnCode int) {
|
||||||
var err error
|
var err error
|
||||||
if viper.GetBool(config.WantReportError) {
|
if viper.GetBool(config.WantReportError) {
|
||||||
|
@ -139,17 +142,24 @@ func MaybeReportErrorAndExitWithCode(errToReport error, returnCode int) {
|
||||||
`================================================================================
|
`================================================================================
|
||||||
An error has occurred. Would you like to opt in to sending anonymized crash
|
An error has occurred. Would you like to opt in to sending anonymized crash
|
||||||
information to minikube to help prevent future errors?
|
information to minikube to help prevent future errors?
|
||||||
To opt out of these messages, run the command:
|
|
||||||
minikube config set WantReportErrorPrompt false
|
To disable this prompt, run: 'minikube config set WantReportErrorPrompt false'
|
||||||
================================================================================`)
|
================================================================================`)
|
||||||
if PromptUserForAccept(os.Stdin) {
|
if PromptUserForAccept(os.Stdin) {
|
||||||
minikubeConfig.Set(config.WantReportError, "true")
|
err = minikubeConfig.Set(config.WantReportError, "true")
|
||||||
err = ReportError(errToReport, constants.ReportingURL)
|
if err == nil {
|
||||||
|
err = ReportError(errToReport, constants.ReportingURL)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Bummer, perhaps next time!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This happens when the error was created without errors.Wrap(), and thus has no trace data.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf(err.Error())
|
glog.Infof("report error failed: %v", err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("\n\nminikube failed :( exiting with error code %d\n", returnCode)
|
||||||
os.Exit(returnCode)
|
os.Exit(returnCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +191,7 @@ func PromptUserForAccept(r io.Reader) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case <-time.After(30 * time.Second):
|
case <-time.After(30 * time.Second):
|
||||||
|
fmt.Println("Prompt timed out.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +231,33 @@ minikube config set WantKubectlDownloadMsg false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a command to run, that will generate the crictl config file
|
||||||
|
func GetCrictlConfigCommand(cfg map[string]string) (string, error) {
|
||||||
|
var (
|
||||||
|
crictlYamlTmpl = `runtime-endpoint: {{.RuntimeEndpoint}}
|
||||||
|
image-endpoint: {{.ImageEndpoint}}
|
||||||
|
`
|
||||||
|
crictlYamlPath = "/etc/crictl.yaml"
|
||||||
|
)
|
||||||
|
t, err := template.New("crictlYaml").Parse(crictlYamlTmpl)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
opts := struct {
|
||||||
|
RuntimeEndpoint string
|
||||||
|
ImageEndpoint string
|
||||||
|
}{
|
||||||
|
RuntimeEndpoint: cfg["runtime-endpoint"],
|
||||||
|
ImageEndpoint: cfg["image-endpoint"],
|
||||||
|
}
|
||||||
|
var crictlYamlBuf bytes.Buffer
|
||||||
|
if err := t.Execute(&crictlYamlBuf, opts); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | sudo tee %s", path.Dir(crictlYamlPath), crictlYamlBuf.String(), crictlYamlPath), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Ask the kernel for a free open port that is ready to use
|
// Ask the kernel for a free open port that is ready to use
|
||||||
func GetPort() (string, error) {
|
func GetPort() (string, error) {
|
||||||
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||||
|
|
|
@ -19,8 +19,10 @@ package util
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -31,6 +33,16 @@ import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func startTestHTTPServer(returnError bool, response string) *httptest.Server {
|
||||||
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if returnError {
|
||||||
|
http.Error(w, response, 400)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, response)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
func TestFormatError(t *testing.T) {
|
func TestFormatError(t *testing.T) {
|
||||||
var testErr error
|
var testErr error
|
||||||
if _, err := FormatError(testErr); err == nil {
|
if _, err := FormatError(testErr); err == nil {
|
||||||
|
@ -70,22 +82,26 @@ func TestUploadError(t *testing.T) {
|
||||||
errMsg, _ := FormatError(testErr)
|
errMsg, _ := FormatError(testErr)
|
||||||
jsonErrMsg, _ := MarshallError(errMsg, "default", version.GetVersion())
|
jsonErrMsg, _ := MarshallError(errMsg, "default", version.GetVersion())
|
||||||
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := startTestHTTPServer(false, "http test")
|
||||||
fmt.Fprintf(w, "Hello, world!")
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err := UploadError(jsonErrMsg, server.URL); err != nil {
|
if err := UploadError(jsonErrMsg, server.URL); err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server = startTestHTTPServer(true, "failed to write report")
|
||||||
http.Error(w, "failed to write report", 400)
|
|
||||||
}))
|
|
||||||
if err := UploadError(jsonErrMsg, server.URL); err == nil {
|
if err := UploadError(jsonErrMsg, server.URL); err == nil {
|
||||||
t.Fatalf("UploadError should have errored from a 400 response")
|
t.Fatalf("UploadError should have errored from a 400 response")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReportError(t *testing.T) {
|
||||||
|
testErr := errors.New("TestError 1")
|
||||||
|
|
||||||
|
server := startTestHTTPServer(false, "http test")
|
||||||
|
if err := ReportError(testErr, server.URL); err != nil {
|
||||||
|
t.Fatalf("ReportError")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func revertLookPath(l LookPath) {
|
func revertLookPath(l LookPath) {
|
||||||
lookPath = l
|
lookPath = l
|
||||||
}
|
}
|
||||||
|
@ -163,3 +179,26 @@ func TestKubectlDownloadMsg(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetKubeConfigPath(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
input string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: "/home/fake/.kube/.kubeconfig",
|
||||||
|
want: "/home/fake/.kube/.kubeconfig",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig",
|
||||||
|
want: "/home/fake/.kube/.kubeconfig",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
os.Setenv(clientcmd.RecommendedConfigPathEnvVar, test.input)
|
||||||
|
if result := GetKubeConfigPath(); result != test.want {
|
||||||
|
t.Errorf("Expected first splitted chunk, got: %s", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ When starting minikube, specify the following flags, along with any additional d
|
||||||
```shell
|
```shell
|
||||||
$ minikube start --container-runtime=containerd \
|
$ minikube start --container-runtime=containerd \
|
||||||
--docker-opt containerd=/var/run/containerd/containerd.sock \
|
--docker-opt containerd=/var/run/containerd/containerd.sock \
|
||||||
--network-plugin=cni
|
--network-plugin=cni --enable-default-cni
|
||||||
```
|
```
|
||||||
|
|
||||||
### Enabling gVisor
|
### Enabling gVisor
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
## storage-provisioner-gluster addon
|
||||||
|
[Gluster](https://gluster.org/), a scalable network filesystem that provides dynamic provisioning of PersistenVolumeClaims.
|
||||||
|
|
||||||
|
### Starting Minikube
|
||||||
|
This addon works within Minikube, without any additional configuration.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ minikube start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Enabling storage-provisioner-gluster
|
||||||
|
To enable this addon, simply run:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ minikube addons enable storage-provisioner-gluster
|
||||||
|
```
|
||||||
|
|
||||||
|
Within one minute, the addon manager should pick up the change and you should see several Pods in the `storage-gluster` namespace:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kubectl -n storage-gluster get pods
|
||||||
|
NAME READY STATUS RESTARTS AGE
|
||||||
|
glusterfile-provisioner-dbcbf54fc-726vv 1/1 Running 0 1m
|
||||||
|
glusterfs-rvdmz 0/1 Running 0 40s
|
||||||
|
heketi-79997b9d85-42c49 0/1 ContainerCreating 0 40s
|
||||||
|
```
|
||||||
|
|
||||||
|
Some of the Pods need a little more time to get up an running than others, but in a few minutes everything should have been deployed and all Pods should be `READY`:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kubectl -n storage-gluster get pods
|
||||||
|
NAME READY STATUS RESTARTS AGE
|
||||||
|
glusterfile-provisioner-dbcbf54fc-726vv 1/1 Running 0 5m
|
||||||
|
glusterfs-rvdmz 1/1 Running 0 4m
|
||||||
|
heketi-79997b9d85-42c49 1/1 Running 1 4m
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the Pods have status `Running`, the `glusterfile` StorageClass should have been marked as `default`:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kubectl get sc
|
||||||
|
NAME PROVISIONER AGE
|
||||||
|
glusterfile (default) gluster.org/glusterfile 3m
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating PVCs
|
||||||
|
The storage in the Gluster environment is limited to 10 GiB. This is because the data is stored in the Minikube VM (a sparse file `/srv/fake-disk.img`).
|
||||||
|
|
||||||
|
The following `yaml` creates a PVC, starts a CentOS developer Pod that generates a website and deploys an NGINX webserver that provides access to the website:
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# Minimal PVC where a developer can build a website.
|
||||||
|
#
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: website
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteMany
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 2Mi
|
||||||
|
storageClassName: glusterfile
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# This pod will just download a fortune phrase and store it (as plain text) in
|
||||||
|
# index.html on the PVC. This is how we create websites?
|
||||||
|
#
|
||||||
|
# The root of the website stored on the above PVC is mounted on /mnt.
|
||||||
|
#
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: centos-webdev
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: centos:latest
|
||||||
|
name: centos
|
||||||
|
args:
|
||||||
|
- curl
|
||||||
|
- -o/mnt/index.html
|
||||||
|
- https://api.ef.gy/fortune
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /mnt
|
||||||
|
name: website
|
||||||
|
# once the website is created, the pod will exit
|
||||||
|
restartPolicy: Never
|
||||||
|
volumes:
|
||||||
|
- name: website
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: website
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# Start a NGINX webserver with the website.
|
||||||
|
# We'll skip creating a service, to keep things minimal.
|
||||||
|
#
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: website-nginx
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: gcr.io/google_containers/nginx-slim:0.8
|
||||||
|
name: nginx
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: web
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /usr/share/nginx/html
|
||||||
|
name: website
|
||||||
|
volumes:
|
||||||
|
- name: website
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: website
|
||||||
|
```
|
||||||
|
|
||||||
|
Because the PVC has been created with the `ReadWriteMany` accessMode, both Pods can access the PVC at the same time. Other website developer Pods can use the same PVC to update the contents of the site.
|
||||||
|
|
||||||
|
The above configuration does not expose the website on the Minikube VM. One way to see the contents of the website is to SSH into the Minikube VM and fetch the website there:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kubectl get pods -o wide
|
||||||
|
NAME READY STATUS RESTARTS AGE IP NODE
|
||||||
|
centos-webdev 0/1 Completed 0 1m 172.17.0.9 minikube
|
||||||
|
website-nginx 1/1 Running 0 24s 172.17.0.9 minikube
|
||||||
|
$ minikube ssh
|
||||||
|
_ _
|
||||||
|
_ _ ( ) ( )
|
||||||
|
___ ___ (_) ___ (_)| |/') _ _ | |_ __
|
||||||
|
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
|
||||||
|
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
|
||||||
|
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
|
||||||
|
|
||||||
|
$ curl http://172.17.0.9
|
||||||
|
I came, I saw, I deleted all your files.
|
||||||
|
$
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
---
|
||||||
|
kind: DaemonSet
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfs
|
||||||
|
labels:
|
||||||
|
glusterfs: daemonset
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
annotations:
|
||||||
|
description: GlusterFS DaemonSet
|
||||||
|
tags: glusterfs
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfs
|
||||||
|
labels:
|
||||||
|
glusterfs: pod
|
||||||
|
glusterfs-node: pod
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
spec:
|
||||||
|
#nodeSelector:
|
||||||
|
# kubernetes.io/hostname: minikube
|
||||||
|
hostNetwork: true
|
||||||
|
containers:
|
||||||
|
- image: quay.io/nixpanic/glusterfs-server:pr_fake-disk
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
name: glusterfs
|
||||||
|
env:
|
||||||
|
- name: USE_FAKE_DISK
|
||||||
|
value: "enabled"
|
||||||
|
#- name: USE_FAKE_FILE
|
||||||
|
# value: "/srv/fake-disk.img"
|
||||||
|
#- name: USE_FAKE_SIZE
|
||||||
|
# value: "10G"
|
||||||
|
#- name: USE_FAKE_DEV
|
||||||
|
# value: "/dev/fake"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 100Mi
|
||||||
|
cpu: 100m
|
||||||
|
volumeMounts:
|
||||||
|
# default location for fake-disk.img, it needs to be persistent
|
||||||
|
- name: fake-disk
|
||||||
|
mountPath: /srv
|
||||||
|
# the fstab for the bricks is under /var/lib/heketi
|
||||||
|
- name: glusterfs-heketi
|
||||||
|
mountPath: "/var/lib/heketi"
|
||||||
|
- name: glusterfs-run
|
||||||
|
mountPath: "/run"
|
||||||
|
- name: glusterfs-lvm
|
||||||
|
mountPath: "/run/lvm"
|
||||||
|
#- name: glusterfs-etc
|
||||||
|
# mountPath: "/etc/glusterfs"
|
||||||
|
- name: glusterfs-logs
|
||||||
|
mountPath: "/var/log/glusterfs"
|
||||||
|
- name: glusterfs-config
|
||||||
|
mountPath: "/var/lib/glusterd"
|
||||||
|
- name: glusterfs-dev
|
||||||
|
mountPath: "/dev"
|
||||||
|
# glusterfind uses /var/lib/misc/glusterfsd, yuck
|
||||||
|
- name: glusterfs-misc
|
||||||
|
mountPath: "/var/lib/misc/glusterfsd"
|
||||||
|
- name: glusterfs-cgroup
|
||||||
|
mountPath: "/sys/fs/cgroup"
|
||||||
|
readOnly: true
|
||||||
|
- name: glusterfs-ssl
|
||||||
|
mountPath: "/etc/ssl"
|
||||||
|
readOnly: true
|
||||||
|
- name: kernel-modules
|
||||||
|
mountPath: "/usr/lib/modules"
|
||||||
|
readOnly: true
|
||||||
|
securityContext:
|
||||||
|
capabilities: {}
|
||||||
|
privileged: true
|
||||||
|
readinessProbe:
|
||||||
|
timeoutSeconds: 3
|
||||||
|
initialDelaySeconds: 40
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- "/bin/bash"
|
||||||
|
- "-c"
|
||||||
|
- systemctl status glusterd.service
|
||||||
|
periodSeconds: 25
|
||||||
|
successThreshold: 1
|
||||||
|
failureThreshold: 50
|
||||||
|
livenessProbe:
|
||||||
|
timeoutSeconds: 3
|
||||||
|
initialDelaySeconds: 40
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- "/bin/bash"
|
||||||
|
- "-c"
|
||||||
|
- systemctl status glusterd.service
|
||||||
|
periodSeconds: 25
|
||||||
|
successThreshold: 1
|
||||||
|
failureThreshold: 50
|
||||||
|
volumes:
|
||||||
|
- name: fake-disk
|
||||||
|
hostPath:
|
||||||
|
path: /srv
|
||||||
|
- name: glusterfs-heketi
|
||||||
|
hostPath:
|
||||||
|
path: "/var/lib/heketi"
|
||||||
|
- name: glusterfs-run
|
||||||
|
- name: glusterfs-lvm
|
||||||
|
hostPath:
|
||||||
|
path: "/run/lvm"
|
||||||
|
- name: glusterfs-etc
|
||||||
|
hostPath:
|
||||||
|
path: "/etc/glusterfs"
|
||||||
|
- name: glusterfs-logs
|
||||||
|
hostPath:
|
||||||
|
path: "/var/log/glusterfs"
|
||||||
|
- name: glusterfs-config
|
||||||
|
hostPath:
|
||||||
|
path: "/var/lib/glusterd"
|
||||||
|
- name: glusterfs-dev
|
||||||
|
hostPath:
|
||||||
|
path: "/dev"
|
||||||
|
- name: glusterfs-misc
|
||||||
|
hostPath:
|
||||||
|
path: "/var/lib/misc/glusterfsd"
|
||||||
|
- name: glusterfs-cgroup
|
||||||
|
hostPath:
|
||||||
|
path: "/sys/fs/cgroup"
|
||||||
|
- name: glusterfs-ssl
|
||||||
|
hostPath:
|
||||||
|
path: "/etc/ssl"
|
||||||
|
- name: kernel-modules
|
||||||
|
hostPath:
|
||||||
|
path: "/usr/lib/modules"
|
|
@ -0,0 +1,158 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi-service-account
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
name: heketi-sa-view
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: edit
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi-service-account
|
||||||
|
---
|
||||||
|
kind: Service
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi
|
||||||
|
labels:
|
||||||
|
glusterfs: heketi-service
|
||||||
|
heketi: service
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
annotations:
|
||||||
|
description: Exposes Heketi Service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
glusterfs: heketi-pod
|
||||||
|
ports:
|
||||||
|
- name: heketi
|
||||||
|
port: 8080
|
||||||
|
targetPort: 8080
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi-topology
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
data:
|
||||||
|
minikube.json: |+
|
||||||
|
{
|
||||||
|
"clusters": [
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"node": {
|
||||||
|
"hostnames": {
|
||||||
|
"manage": [
|
||||||
|
"minikube"
|
||||||
|
],
|
||||||
|
"storage": [
|
||||||
|
"172.17.0.1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"zone": 1
|
||||||
|
},
|
||||||
|
"devices": [
|
||||||
|
"/dev/fake"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: Deployment
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi
|
||||||
|
labels:
|
||||||
|
glusterfs: heketi-deployment
|
||||||
|
heketi: deployment
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
annotations:
|
||||||
|
description: Defines how to deploy Heketi
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: heketi
|
||||||
|
labels:
|
||||||
|
glusterfs: heketi-pod
|
||||||
|
heketi: pod
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
spec:
|
||||||
|
serviceAccountName: heketi-service-account
|
||||||
|
containers:
|
||||||
|
- image: heketi/heketi:latest
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
name: heketi
|
||||||
|
env:
|
||||||
|
- name: HEKETI_EXECUTOR
|
||||||
|
value: "kubernetes"
|
||||||
|
- name: HEKETI_FSTAB
|
||||||
|
value: "/var/lib/heketi/fstab"
|
||||||
|
- name: HEKETI_SNAPSHOT_LIMIT
|
||||||
|
value: '14'
|
||||||
|
- name: HEKETI_KUBE_GLUSTER_DAEMONSET
|
||||||
|
value: "y"
|
||||||
|
- name: HEKETI_IGNORE_STALE_OPERATIONS
|
||||||
|
value: "true"
|
||||||
|
- name: HEKETI_GLUSTERAPP_LOGLEVEL
|
||||||
|
value: "debug"
|
||||||
|
# initial topology.json in case the db does not exist
|
||||||
|
- name: HEKETI_TOPOLOGY_FILE
|
||||||
|
value: "/etc/heketi/topology/minikube.json"
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
volumeMounts:
|
||||||
|
- name: db
|
||||||
|
mountPath: "/var/lib/heketi"
|
||||||
|
- name: initial-topology
|
||||||
|
mountPath: "/etc/heketi/topology"
|
||||||
|
readinessProbe:
|
||||||
|
timeoutSeconds: 3
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
httpGet:
|
||||||
|
path: "/hello"
|
||||||
|
port: 8080
|
||||||
|
livenessProbe:
|
||||||
|
timeoutSeconds: 3
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
httpGet:
|
||||||
|
path: "/hello"
|
||||||
|
port: 8080
|
||||||
|
volumes:
|
||||||
|
- name: db
|
||||||
|
hostPath:
|
||||||
|
path: "/var/lib/heketi"
|
||||||
|
- name: initial-topology
|
||||||
|
configMap:
|
||||||
|
name: heketi-topology
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: storage-gluster
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
|
@ -0,0 +1,109 @@
|
||||||
|
---
|
||||||
|
kind: StorageClass
|
||||||
|
apiVersion: storage.k8s.io/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: glusterfile
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: EnsureExists
|
||||||
|
annotations:
|
||||||
|
storageclass.beta.kubernetes.io/is-default-class: "true"
|
||||||
|
provisioner: gluster.org/glusterfile
|
||||||
|
reclaimPolicy: Delete
|
||||||
|
parameters:
|
||||||
|
resturl: "http://heketi.storage-gluster.svc.cluster.local:8080"
|
||||||
|
restuser: admin
|
||||||
|
---
|
||||||
|
kind: ClusterRole
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: glusterfile-provisioner-runner
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["persistentvolumes"]
|
||||||
|
verbs: ["get", "list", "watch", "create", "delete"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["persistentvolumeclaims"]
|
||||||
|
verbs: ["get", "list", "watch", "update"]
|
||||||
|
- apiGroups: ["storage.k8s.io"]
|
||||||
|
resources: ["storageclasses"]
|
||||||
|
verbs: ["get", "list", "watch"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["events"]
|
||||||
|
verbs: ["list", "watch", "create", "update", "patch"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["services"]
|
||||||
|
verbs: ["get","create","delete"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["secrets"]
|
||||||
|
verbs: ["get"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["routes"]
|
||||||
|
verbs: ["get", "list"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["endpoints"]
|
||||||
|
verbs: ["get", "create","delete"]
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfile-provisioner
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: glusterfile-provisioner
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
roleRef:
|
||||||
|
kind: ClusterRole
|
||||||
|
name: glusterfile-provisioner-runner
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfile-provisioner
|
||||||
|
---
|
||||||
|
kind: Deployment
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfile-provisioner
|
||||||
|
labels:
|
||||||
|
k8s-app: storage-provisioner-gluster
|
||||||
|
kubernetes.io/minikube-addons: storage-provisioner-gluster
|
||||||
|
addonmanager.kubernetes.io/mode: Reconcile
|
||||||
|
annotations:
|
||||||
|
description: Defines how to deploy the glusterfile provisioner pod.
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
namespace: storage-gluster
|
||||||
|
name: glusterfile-provisioner
|
||||||
|
labels:
|
||||||
|
glusterfs: file-provisioner-pod
|
||||||
|
glusterfile: provisioner-pod
|
||||||
|
spec:
|
||||||
|
serviceAccountName: glusterfile-provisioner
|
||||||
|
containers:
|
||||||
|
- name: glusterfile-provisioner
|
||||||
|
image: gluster/glusterfile-provisioner:latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
env:
|
||||||
|
- name: PROVISIONER_NAME
|
||||||
|
value: gluster.org/glusterfile
|
|
@ -6,6 +6,6 @@ metadata:
|
||||||
annotations:
|
annotations:
|
||||||
storageclass.beta.kubernetes.io/is-default-class: "true"
|
storageclass.beta.kubernetes.io/is-default-class: "true"
|
||||||
labels:
|
labels:
|
||||||
addonmanager.kubernetes.io/mode: Reconcile
|
addonmanager.kubernetes.io/mode: EnsureExists
|
||||||
|
|
||||||
provisioner: k8s.io/minikube-hostpath
|
provisioner: k8s.io/minikube-hostpath
|
||||||
|
|
|
@ -319,6 +319,7 @@ CONFIG_NETDEVICES=y
|
||||||
CONFIG_DUMMY=m
|
CONFIG_DUMMY=m
|
||||||
CONFIG_MACVLAN=y
|
CONFIG_MACVLAN=y
|
||||||
CONFIG_MACVTAP=y
|
CONFIG_MACVTAP=y
|
||||||
|
CONFIG_IPVLAN=m
|
||||||
CONFIG_VXLAN=y
|
CONFIG_VXLAN=y
|
||||||
CONFIG_NETCONSOLE=y
|
CONFIG_NETCONSOLE=y
|
||||||
CONFIG_TUN=y
|
CONFIG_TUN=y
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../../../usr/libexec/kubernetes/kubelet-plugins/net/exec/k8s.conf
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"name": "rkt.kubernetes.io",
|
|
||||||
"type": "bridge",
|
|
||||||
"bridge": "mybridge",
|
|
||||||
"mtu": 1460,
|
|
||||||
"addIf": "true",
|
|
||||||
"isGateway": true,
|
|
||||||
"ipMasq": true,
|
|
||||||
"ipam": {
|
|
||||||
"type": "host-local",
|
|
||||||
"subnet": "10.1.0.0/16",
|
|
||||||
"gateway": "10.1.0.1",
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"dst": "0.0.0.0/0"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"name": "rkt.kubernetes.io",
|
|
||||||
"type": "bridge",
|
|
||||||
"bridge": "mybridge",
|
|
||||||
"mtu": 1460,
|
|
||||||
"addIf": "true",
|
|
||||||
"isGateway": true,
|
|
||||||
"ipMasq": true,
|
|
||||||
"ipam": {
|
|
||||||
"type": "host-local",
|
|
||||||
"subnet": "10.1.0.0/16",
|
|
||||||
"gateway": "10.1.0.1",
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"dst": "0.0.0.0/0"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -124,6 +124,10 @@ if [ -n "$BOOT2DOCKER_DATA" ]; then
|
||||||
mkdir -p /var/lib/docker
|
mkdir -p /var/lib/docker
|
||||||
mount --bind /mnt/$PARTNAME/var/lib/docker /var/lib/docker
|
mount --bind /mnt/$PARTNAME/var/lib/docker /var/lib/docker
|
||||||
|
|
||||||
|
mkdir -p /mnt/$PARTNAME/var/lib/containers
|
||||||
|
mkdir -p /var/lib/containers
|
||||||
|
mount --bind /mnt/$PARTNAME/var/lib/containers /var/lib/containers
|
||||||
|
|
||||||
mkdir -p /mnt/$PARTNAME/var/log
|
mkdir -p /mnt/$PARTNAME/var/log
|
||||||
mkdir /var/log
|
mkdir /var/log
|
||||||
mount --bind /mnt/$PARTNAME/var/log /var/log
|
mount --bind /mnt/$PARTNAME/var/log /var/log
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
sha256 d310d52706262009af886dbd3e8dcd09a339cdc3b57dc22a9121e6d6a87d2921 v1.8.4.tar.gz
|
sha256 d310d52706262009af886dbd3e8dcd09a339cdc3b57dc22a9121e6d6a87d2921 v1.8.4.tar.gz
|
||||||
sha256 9f79cee99e272c9cfc561ae31235d84d4da59fd5c8b3d3ab6623bf9a92d90c5a v1.10.0.tar.gz
|
sha256 9f79cee99e272c9cfc561ae31235d84d4da59fd5c8b3d3ab6623bf9a92d90c5a v1.10.0.tar.gz
|
||||||
sha256 09e53fd550f4f10108879131ee6b8ef1c367ce71a73dcf6350c4cc898751d8c1 v1.11.8.tar.gz
|
sha256 09e53fd550f4f10108879131ee6b8ef1c367ce71a73dcf6350c4cc898751d8c1 v1.11.8.tar.gz
|
||||||
|
sha256 92588998dbb79002c38f65f84602b5659f0d0ef1cd36b1a568a2e40269b66816 v1.13.0.tar.gz
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
CRIO_BIN_VERSION = v1.11.8
|
CRIO_BIN_VERSION = v1.13.0
|
||||||
CRIO_BIN_SITE = https://github.com/kubernetes-sigs/cri-o/archive
|
CRIO_BIN_SITE = https://github.com/kubernetes-sigs/cri-o/archive
|
||||||
CRIO_BIN_SOURCE = $(CRIO_BIN_VERSION).tar.gz
|
CRIO_BIN_SOURCE = $(CRIO_BIN_VERSION).tar.gz
|
||||||
CRIO_BIN_DEPENDENCIES = host-go libgpgme
|
CRIO_BIN_DEPENDENCIES = host-go libgpgme
|
||||||
|
@ -56,7 +56,7 @@ define CRIO_BIN_INSTALL_TARGET_CMDS
|
||||||
$(TARGET_DIR)/etc/containers/policy.json
|
$(TARGET_DIR)/etc/containers/policy.json
|
||||||
|
|
||||||
mkdir -p $(TARGET_DIR)/etc/sysconfig
|
mkdir -p $(TARGET_DIR)/etc/sysconfig
|
||||||
echo 'CRIO_OPTIONS="--storage-driver=overlay2 --log-level=debug"' > $(TARGET_DIR)/etc/sysconfig/crio
|
echo 'CRIO_OPTIONS="--log-level=debug"' > $(TARGET_DIR)/etc/sysconfig/crio
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define CRIO_BIN_INSTALL_INIT_SYSTEMD
|
define CRIO_BIN_INSTALL_INIT_SYSTEMD
|
||||||
|
|
|
@ -12,7 +12,7 @@ runroot = "/var/run/containers/storage"
|
||||||
|
|
||||||
# storage_driver select which storage driver is used to manage storage
|
# storage_driver select which storage driver is used to manage storage
|
||||||
# of images and containers.
|
# of images and containers.
|
||||||
storage_driver = ""
|
storage_driver = "overlay"
|
||||||
|
|
||||||
# storage_option is used to pass an option to the storage driver.
|
# storage_option is used to pass an option to the storage driver.
|
||||||
storage_option = [
|
storage_option = [
|
||||||
|
@ -146,6 +146,7 @@ insecure_registries = [
|
||||||
# registries is used to specify a comma separated list of registries to be used
|
# registries is used to specify a comma separated list of registries to be used
|
||||||
# when pulling an unqualified image (e.g. fedora:rawhide).
|
# when pulling an unqualified image (e.g. fedora:rawhide).
|
||||||
registries = [
|
registries = [
|
||||||
|
"docker.io"
|
||||||
]
|
]
|
||||||
|
|
||||||
# The "crio.network" table contains settings pertaining to the
|
# The "crio.network" table contains settings pertaining to the
|
||||||
|
|
|
@ -10,11 +10,9 @@ EnvironmentFile=-/etc/sysconfig/crio
|
||||||
EnvironmentFile=-/etc/sysconfig/crio.minikube
|
EnvironmentFile=-/etc/sysconfig/crio.minikube
|
||||||
EnvironmentFile=/var/run/minikube/env
|
EnvironmentFile=/var/run/minikube/env
|
||||||
Environment=GOTRACEBACK=crash
|
Environment=GOTRACEBACK=crash
|
||||||
ExecStartPre=/bin/mkdir -p ${PERSISTENT_DIR}/var/lib/containers
|
|
||||||
ExecStart=/usr/bin/crio \
|
ExecStart=/usr/bin/crio \
|
||||||
$CRIO_OPTIONS \
|
$CRIO_OPTIONS \
|
||||||
$CRIO_MINIKUBE_OPTIONS \
|
$CRIO_MINIKUBE_OPTIONS
|
||||||
--root ${PERSISTENT_DIR}/var/lib/containers
|
|
||||||
ExecReload=/bin/kill -s HUP $MAINPID
|
ExecReload=/bin/kill -s HUP $MAINPID
|
||||||
TasksMax=8192
|
TasksMax=8192
|
||||||
LimitNOFILE=1048576
|
LimitNOFILE=1048576
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
# Locally computed
|
# Locally computed
|
||||||
sha256 fc780966c4d70c275a87930e93cda4210e63a490eabfb0fa5f2fe70be6dcdc58 0fdc908bf1ee7b7da85f9e5adbd1e256060f2486.tar.gz
|
sha256 fc780966c4d70c275a87930e93cda4210e63a490eabfb0fa5f2fe70be6dcdc58 0fdc908bf1ee7b7da85f9e5adbd1e256060f2486.tar.gz
|
||||||
|
sha256 9318fa9de6e3b2c89760f08d73bf718c97c93d683611716e024d2f3283c96d90 c1e454b2a1bfb0f0ebd9e621a1433f98f9a8d4b0.tar.gz
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
RUNC_MASTER_VERSION = 0fdc908bf1ee7b7da85f9e5adbd1e256060f2486
|
# HEAD as of 2019-01-15
|
||||||
|
RUNC_MASTER_VERSION = c1e454b2a1bfb0f0ebd9e621a1433f98f9a8d4b0
|
||||||
RUNC_MASTER_SITE = https://github.com/opencontainers/runc/archive
|
RUNC_MASTER_SITE = https://github.com/opencontainers/runc/archive
|
||||||
RUNC_MASTER_SOURCE = $(RUNC_MASTER_VERSION).tar.gz
|
RUNC_MASTER_SOURCE = $(RUNC_MASTER_VERSION).tar.gz
|
||||||
RUNC_MASTER_LICENSE = Apache-2.0
|
RUNC_MASTER_LICENSE = Apache-2.0
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
[
|
[
|
||||||
|
{
|
||||||
|
"name": "v0.32.0",
|
||||||
|
"checksums": {
|
||||||
|
"darwin": "d5b21adacd4b6bad9006816e4bdb29f39318a60919e7a6bb5e388a6299fffd0f",
|
||||||
|
"linux": "3298d3183deacd9ddd3032dab113a64d863df7648d6d24693284ba4193e95b49",
|
||||||
|
"windows": "31668f64f6be25644b22d0465e0f72d745a027804b2c8685e040b8147bacfba1"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "v0.31.0",
|
"name": "v0.31.0",
|
||||||
"checksums": {
|
"checksums": {
|
||||||
|
|
|
@ -13,6 +13,7 @@ $ minikube addons list
|
||||||
- ingress: disabled
|
- ingress: disabled
|
||||||
- default-storageclass: enabled
|
- default-storageclass: enabled
|
||||||
- storage-provisioner: enabled
|
- storage-provisioner: enabled
|
||||||
|
- storage-provisioner-gluster: disabled
|
||||||
- nvidia-driver-installer: disabled
|
- nvidia-driver-installer: disabled
|
||||||
- nvidia-gpu-device-plugin: disabled
|
- nvidia-gpu-device-plugin: disabled
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ The currently supported addons include:
|
||||||
* [nvidia-driver-installer](https://github.com/GoogleCloudPlatform/container-engine-accelerators/tree/master/nvidia-driver-installer/minikube)
|
* [nvidia-driver-installer](https://github.com/GoogleCloudPlatform/container-engine-accelerators/tree/master/nvidia-driver-installer/minikube)
|
||||||
* [nvidia-gpu-device-plugin](https://github.com/GoogleCloudPlatform/container-engine-accelerators/tree/master/cmd/nvidia_gpu)
|
* [nvidia-gpu-device-plugin](https://github.com/GoogleCloudPlatform/container-engine-accelerators/tree/master/cmd/nvidia_gpu)
|
||||||
* [gvisor](../deploy/addons/gvisor/README.md)
|
* [gvisor](../deploy/addons/gvisor/README.md)
|
||||||
|
* [storage-provisioner-gluster](../deploy/addons/storage-provisioner-gluster/README.md)
|
||||||
|
|
||||||
If you would like to have minikube properly start/restart custom addons, place the addon(s) you wish to be launched with minikube in the `.minikube/addons` directory. Addons in this folder will be moved to the minikube VM and launched each time minikube is started/restarted.
|
If you would like to have minikube properly start/restart custom addons, place the addon(s) you wish to be launched with minikube in the `.minikube/addons` directory. Addons in this folder will be moved to the minikube VM and launched each time minikube is started/restarted.
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ To use [rkt](https://github.com/coreos/rkt) as the container runtime run:
|
||||||
```shell
|
```shell
|
||||||
$ minikube start \
|
$ minikube start \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
--container-runtime=rkt
|
--container-runtime=rkt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ To use [CRI-O](https://github.com/kubernetes-incubator/cri-o) as the container r
|
||||||
```shell
|
```shell
|
||||||
$ minikube start \
|
$ minikube start \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
--container-runtime=cri-o
|
--container-runtime=cri-o
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -24,6 +26,8 @@ Or you can use the extended version:
|
||||||
```shell
|
```shell
|
||||||
$ minikube start \
|
$ minikube start \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
|
--container-runtime=cri-o \
|
||||||
--cri-socket=/var/run/crio/crio.sock \
|
--cri-socket=/var/run/crio/crio.sock \
|
||||||
--extra-config=kubelet.container-runtime=remote \
|
--extra-config=kubelet.container-runtime=remote \
|
||||||
--extra-config=kubelet.container-runtime-endpoint=unix:///var/run/crio/crio.sock \
|
--extra-config=kubelet.container-runtime-endpoint=unix:///var/run/crio/crio.sock \
|
||||||
|
@ -37,6 +41,7 @@ To use [containerd](https://github.com/containerd/containerd) as the container r
|
||||||
```shell
|
```shell
|
||||||
$ minikube start \
|
$ minikube start \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
--container-runtime=containerd
|
--container-runtime=containerd
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -45,6 +50,8 @@ Or you can use the extended version:
|
||||||
```shell
|
```shell
|
||||||
$ minikube start \
|
$ minikube start \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
|
--container-runtime=containerd \
|
||||||
--cri-socket=/run/containerd/containerd.sock \
|
--cri-socket=/run/containerd/containerd.sock \
|
||||||
--extra-config=kubelet.container-runtime=remote \
|
--extra-config=kubelet.container-runtime=remote \
|
||||||
--extra-config=kubelet.container-runtime-endpoint=unix:///run/containerd/containerd.sock \
|
--extra-config=kubelet.container-runtime-endpoint=unix:///run/containerd/containerd.sock \
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
### Build Requirements
|
### Build Requirements
|
||||||
* A recent Go distribution (>1.8)
|
* A recent Go distribution (>=1.11)
|
||||||
* If you're not on Linux, you'll need a Docker installation
|
* If you're not on Linux, you'll need a Docker installation
|
||||||
* Minikube requires at least 4GB of RAM to compile, which can be problematic when using docker-machine
|
* Minikube requires at least 4GB of RAM to compile, which can be problematic when using docker-machine
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ export KUBERNETES_CONFORMANCE_TEST=y
|
||||||
```
|
```
|
||||||
* Run the tests (from the k8s repo):
|
* Run the tests (from the k8s repo):
|
||||||
```shell
|
```shell
|
||||||
go run hack/e2e.go -v --test --test_args="--ginkgo.focus=\[Conformance\]" --check_version_skew=false --check_node_count=false
|
go run hack/e2e.go -v --test --test_args="--ginkgo.focus=\[Conformance\]" --check-version-skew=false
|
||||||
```
|
```
|
||||||
|
|
||||||
To run a specific conformance test, you can use the `ginkgo.focus` flag to filter the set using a regular expression.
|
To run a specific conformance test, you can use the `ginkgo.focus` flag to filter the set using a regular expression.
|
||||||
|
@ -91,5 +91,5 @@ The `hack/e2e.go` wrapper and the `e2e.sh` wrappers have a little trouble with q
|
||||||
For example, to run the test `should update annotations on modification [Conformance]`, use following command:
|
For example, to run the test `should update annotations on modification [Conformance]`, use following command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run hack/e2e.go -v --test --test_args="--ginkgo.focus=should\supdate\sannotations\son\smodification" --check_version_skew=false --check_node_count=false
|
go run hack/e2e.go -v --test --test_args="--ginkgo.focus=should\supdate\sannotations\son\smodification" --check-version-skew=false
|
||||||
```
|
```
|
||||||
|
|
|
@ -40,6 +40,7 @@ The bootable ISO image will be available in `out/minikube.iso`.
|
||||||
$ ./out/minikube start \
|
$ ./out/minikube start \
|
||||||
--container-runtime=rkt \
|
--container-runtime=rkt \
|
||||||
--network-plugin=cni \
|
--network-plugin=cni \
|
||||||
|
--enable-default-cni \
|
||||||
--iso-url=file://$GOPATH/src/k8s.io/minikube/out/minikube.iso
|
--iso-url=file://$GOPATH/src/k8s.io/minikube/out/minikube.iso
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,11 @@ This roadmap is a living document outlining the major technical improvements whi
|
||||||
|
|
||||||
## (#5) Improve performance
|
## (#5) Improve performance
|
||||||
|
|
||||||
- Add support for lightweight deployment methods for environments where VM's are impractical
|
|
||||||
- Reduce guest VM overhead by 50%
|
- Reduce guest VM overhead by 50%
|
||||||
|
- Support lightweight deployment methods for environments where VM's are impractical
|
||||||
|
|
||||||
## (#6) Reduce technical debt
|
## (#6) Reduce technical debt
|
||||||
|
|
||||||
- Replace built-in machine drivers (virtualbox, kvm2) with their upstream equivalents
|
- Replace built-in machine drivers (virtualbox, kvm2) with their upstream equivalents
|
||||||
- Remove dependency on boot2docker (deprecated)
|
- Remove dependency on boot2docker (deprecated)
|
||||||
|
|
|
@ -14,6 +14,7 @@ the host PATH:
|
||||||
* [Hyperkit](#hyperkit-driver)
|
* [Hyperkit](#hyperkit-driver)
|
||||||
* [xhyve](#xhyve-driver)
|
* [xhyve](#xhyve-driver)
|
||||||
* [HyperV](#hyperv-driver)
|
* [HyperV](#hyperv-driver)
|
||||||
|
* [VMware](#vmware-unified-driver)
|
||||||
|
|
||||||
#### KVM2 driver
|
#### KVM2 driver
|
||||||
|
|
||||||
|
@ -83,7 +84,18 @@ minikube start --vm-driver kvm
|
||||||
The Hyperkit driver will eventually replace the existing xhyve driver.
|
The Hyperkit driver will eventually replace the existing xhyve driver.
|
||||||
It is built from the minikube source tree, and uses [moby/hyperkit](http://github.com/moby/hyperkit) as a Go library.
|
It is built from the minikube source tree, and uses [moby/hyperkit](http://github.com/moby/hyperkit) as a Go library.
|
||||||
|
|
||||||
To install the hyperkit driver:
|
To install the hyperkit driver via brew:
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
brew install docker-machine-driver-hyperkit
|
||||||
|
|
||||||
|
# docker-machine-driver-hyperkit need root owner and uid
|
||||||
|
sudo chown root:wheel /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
|
||||||
|
sudo chmod u+s /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
|
||||||
|
```
|
||||||
|
|
||||||
|
To install the hyperkit driver manually:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \
|
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \
|
||||||
|
@ -115,3 +127,25 @@ sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machi
|
||||||
Hyper-v users may need to create a new external network switch as described [here](https://docs.docker.com/machine/drivers/hyper-v/). This step may prevent a problem in which `minikube start` hangs indefinitely, unable to ssh into the minikube virtual machine. In this add, add the `--hyperv-virtual-switch=switch-name` argument to the `minikube start` command.
|
Hyper-v users may need to create a new external network switch as described [here](https://docs.docker.com/machine/drivers/hyper-v/). This step may prevent a problem in which `minikube start` hangs indefinitely, unable to ssh into the minikube virtual machine. In this add, add the `--hyperv-virtual-switch=switch-name` argument to the `minikube start` command.
|
||||||
|
|
||||||
On some machines, having **dynamic memory management** turned on for the minikube VM can cause problems of unexpected and random restarts which manifests itself in simply losing the connection to the cluster, after which `minikube status` would simply state `stopped`. Machine restarts are caused due to following Hyper-V error: `The dynamic memory balancer could not add memory to the virtual machine 'minikube' because its configured maximum has been reached`. **Solution**: turned the dynamic memory management in hyper-v settings off (and allocate a fixed amount of memory to the machine).
|
On some machines, having **dynamic memory management** turned on for the minikube VM can cause problems of unexpected and random restarts which manifests itself in simply losing the connection to the cluster, after which `minikube status` would simply state `stopped`. Machine restarts are caused due to following Hyper-V error: `The dynamic memory balancer could not add memory to the virtual machine 'minikube' because its configured maximum has been reached`. **Solution**: turned the dynamic memory management in hyper-v settings off (and allocate a fixed amount of memory to the machine).
|
||||||
|
|
||||||
|
#### VMware unified driver
|
||||||
|
|
||||||
|
The VMware unified driver will eventually replace the existing vmwarefusion driver.
|
||||||
|
The new unified driver supports both VMware Fusion (on macOS) and VMware Workstation (on Linux and Windows)
|
||||||
|
|
||||||
|
To install the vmware unified driver, head over at https://github.com/machine-drivers/docker-machine-driver-vmware/releases and download the release for your operating system.
|
||||||
|
|
||||||
|
The driver must be:
|
||||||
|
|
||||||
|
1. Stored in `$PATH`
|
||||||
|
2. Named `docker-machine-driver-vmware`
|
||||||
|
3. Executable (`chmod +x` on UNIX based platforms)
|
||||||
|
|
||||||
|
If you're running on macOS with Fusion, this is an easy way install the driver:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export LATEST_VERSION=$(curl -L -s -H 'Accept: application/json' https://github.com/machine-drivers/docker-machine-driver-vmware/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') \
|
||||||
|
&& curl -L -o docker-machine-driver-vmware https://github.com/machine-drivers/docker-machine-driver-vmware/releases/download/$LATEST_VERSION/docker-machine-driver-vmware_darwin_amd64 \
|
||||||
|
&& chmod +x docker-machine-driver-vmware \
|
||||||
|
&& mv docker-machine-driver-vmware /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Generate go dependencies, for make. Uses `go list".
|
# Generate go dependencies, for make. Uses `go list`.
|
||||||
# Usage: makedepend.sh [-t] output package path [extra]
|
# Usage: makedepend.sh [-t] output package extra path...
|
||||||
|
|
||||||
PATH_FORMAT='{{ .ImportPath }}{{"\n"}}{{join .Deps "\n"}}'
|
PATH_FORMAT='{{ .ImportPath }}{{"\n"}}{{join .Deps "\n"}}'
|
||||||
FILE_FORMAT='{{ range $file := .GoFiles }} {{$.Dir}}/{{$file}}{{"\n"}}{{end}}'
|
FILE_FORMAT='{{ range $file := .GoFiles }} {{$.Dir}}/{{$file}}{{"\n"}}{{end}}'
|
||||||
|
@ -28,14 +28,14 @@ fi
|
||||||
|
|
||||||
out=$1
|
out=$1
|
||||||
pkg=$2
|
pkg=$2
|
||||||
path=$3
|
extra=$3
|
||||||
extra=$4
|
paths="$4 $5 $6"
|
||||||
|
|
||||||
# check for mandatory parameters
|
# check for mandatory parameters
|
||||||
test -n "$out$pkg$path" || exit 1
|
test -n "$out$pkg$paths" || exit 1
|
||||||
|
|
||||||
echo "$out: $extra\\"
|
echo "$out: $extra\\"
|
||||||
go list -f "$PATH_FORMAT" $path |
|
go list -f "$PATH_FORMAT" $paths |
|
||||||
grep "$pkg" |
|
grep "$pkg" |
|
||||||
xargs go list -f "$FILE_FORMAT" |
|
xargs go list -f "$FILE_FORMAT" |
|
||||||
sed -e "s|^ ${GOPATH}| \$(GOPATH)|;s/$/ \\\\/"
|
sed -e "s|^ ${GOPATH}| \$(GOPATH)|;s/$/ \\\\/"
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
hyperkit "github.com/moby/hyperkit/go"
|
hyperkit "github.com/moby/hyperkit/go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
pkgdrivers "k8s.io/minikube/pkg/drivers"
|
pkgdrivers "k8s.io/minikube/pkg/drivers"
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
commonutil "k8s.io/minikube/pkg/util"
|
commonutil "k8s.io/minikube/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ func NewDriver(hostName, storePath string) *Driver {
|
||||||
SSHUser: "docker",
|
SSHUser: "docker",
|
||||||
},
|
},
|
||||||
CommonDriver: &pkgdrivers.CommonDriver{},
|
CommonDriver: &pkgdrivers.CommonDriver{},
|
||||||
|
DiskSize: commonutil.CalculateDiskSizeInMB(constants.DefaultDiskSize),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@ package hyperkit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
|
|
||||||
|
commonutil "k8s.io/minikube/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_portExtraction(t *testing.T) {
|
func Test_portExtraction(t *testing.T) {
|
||||||
|
@ -62,6 +66,15 @@ func Test_portExtraction(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_defaultDiskSize(t *testing.T) {
|
||||||
|
expectedDefaultDiscSize := commonutil.CalculateDiskSizeInMB(constants.DefaultDiskSize)
|
||||||
|
driver := NewDriver("", "")
|
||||||
|
got := driver.DiskSize
|
||||||
|
if got != expectedDefaultDiscSize {
|
||||||
|
t.Errorf("Unexpected default disk size got: %v, want: %v", got, expectedDefaultDiscSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testEq(a, b []int) bool {
|
func testEq(a, b []int) bool {
|
||||||
|
|
||||||
if a == nil && b == nil {
|
if a == nil && b == nil {
|
||||||
|
|
|
@ -74,7 +74,7 @@ var Addons = map[string]*Addon{
|
||||||
constants.AddonsPath,
|
constants.AddonsPath,
|
||||||
"dashboard-svc.yaml",
|
"dashboard-svc.yaml",
|
||||||
"0640"),
|
"0640"),
|
||||||
}, true, "dashboard"),
|
}, false, "dashboard"),
|
||||||
"default-storageclass": NewAddon([]*BinDataAsset{
|
"default-storageclass": NewAddon([]*BinDataAsset{
|
||||||
NewBinDataAsset(
|
NewBinDataAsset(
|
||||||
"deploy/addons/storageclass/storageclass.yaml",
|
"deploy/addons/storageclass/storageclass.yaml",
|
||||||
|
@ -89,6 +89,45 @@ var Addons = map[string]*Addon{
|
||||||
"storage-provisioner.yaml",
|
"storage-provisioner.yaml",
|
||||||
"0640"),
|
"0640"),
|
||||||
}, true, "storage-provisioner"),
|
}, true, "storage-provisioner"),
|
||||||
|
"storage-provisioner-gluster": NewAddon([]*BinDataAsset{
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/storage-provisioner-gluster/storage-gluster-ns.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"storage-gluster-ns.yaml",
|
||||||
|
"0640"),
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/storage-provisioner-gluster/glusterfs-daemonset.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"glusterfs-daemonset.yaml",
|
||||||
|
"0640"),
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/storage-provisioner-gluster/heketi-deployment.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"heketi-deployment.yaml",
|
||||||
|
"0640"),
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/storage-provisioner-gluster/storage-provisioner-glusterfile.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"storage-privisioner-glusterfile.yaml",
|
||||||
|
"0640"),
|
||||||
|
}, false, "storage-provisioner-gluster"),
|
||||||
|
"kube-dns": NewAddon([]*BinDataAsset{
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/kube-dns/kube-dns-controller.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"kube-dns-controller.yaml",
|
||||||
|
"0640"),
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/kube-dns/kube-dns-cm.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"kube-dns-cm.yaml",
|
||||||
|
"0640"),
|
||||||
|
NewBinDataAsset(
|
||||||
|
"deploy/addons/kube-dns/kube-dns-svc.yaml",
|
||||||
|
constants.AddonsPath,
|
||||||
|
"kube-dns-svc.yaml",
|
||||||
|
"0640"),
|
||||||
|
}, false, "kube-dns"),
|
||||||
"heapster": NewAddon([]*BinDataAsset{
|
"heapster": NewAddon([]*BinDataAsset{
|
||||||
NewBinDataAsset(
|
NewBinDataAsset(
|
||||||
"deploy/addons/heapster/influx-grafana-rc.yaml",
|
"deploy/addons/heapster/influx-grafana-rc.yaml",
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kubeadm
|
||||||
|
|
||||||
|
// defaultCNIConfig is the CNI config which is provisioned when --enable-default-cni
|
||||||
|
// has been passed to `minikube start`.
|
||||||
|
//
|
||||||
|
// The config is being written to /etc/cni/net.d/k8s.conf and /etc/rkt/net.d/k8s.conf.
|
||||||
|
const defaultCNIConfig = `
|
||||||
|
{
|
||||||
|
"name": "rkt.kubernetes.io",
|
||||||
|
"type": "bridge",
|
||||||
|
"bridge": "mybridge",
|
||||||
|
"mtu": 1460,
|
||||||
|
"addIf": "true",
|
||||||
|
"isGateway": true,
|
||||||
|
"ipMasq": true,
|
||||||
|
"ipam": {
|
||||||
|
"type": "host-local",
|
||||||
|
"subnet": "10.1.0.0/16",
|
||||||
|
"gateway": "10.1.0.1",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"dst": "0.0.0.0/0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
|
@ -170,7 +170,7 @@ func (k *KubeadmBootstrapper) StartCluster(k8s config.KubernetesConfig) error {
|
||||||
|
|
||||||
out, err := k.c.CombinedOutput(b.String())
|
out, err := k.c.CombinedOutput(b.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "kubeadm init error %s running command: %s", b.String(), out)
|
return errors.Wrapf(err, "kubeadm init: %s\n%s\n", b.String(), out)
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.LT(semver.MustParse("1.10.0-alpha.0")) {
|
if version.LT(semver.MustParse("1.10.0-alpha.0")) {
|
||||||
|
@ -309,6 +309,11 @@ func NewKubeletConfig(k8s config.KubernetesConfig) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extraOpts = SetContainerRuntime(extraOpts, k8s.ContainerRuntime)
|
extraOpts = SetContainerRuntime(extraOpts, k8s.ContainerRuntime)
|
||||||
|
|
||||||
|
if k8s.NetworkPlugin != "" {
|
||||||
|
extraOpts["network-plugin"] = k8s.NetworkPlugin
|
||||||
|
}
|
||||||
|
|
||||||
extraFlags := convertToFlags(extraOpts)
|
extraFlags := convertToFlags(extraOpts)
|
||||||
|
|
||||||
// parses a map of the feature gates for kubelet
|
// parses a map of the feature gates for kubelet
|
||||||
|
@ -358,6 +363,15 @@ func (k *KubeadmBootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
|
||||||
assets.NewMemoryAssetTarget([]byte(kubeadmCfg), constants.KubeadmConfigFile, "0640"),
|
assets.NewMemoryAssetTarget([]byte(kubeadmCfg), constants.KubeadmConfigFile, "0640"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the default CNI config (k8s.conf), so that kubelet can successfully
|
||||||
|
// start a Pod in the case a user hasn't manually installed any CNI plugin
|
||||||
|
// and minikube was started with "--extra-config=kubelet.network-plugin=cni".
|
||||||
|
if cfg.EnableDefaultCNI {
|
||||||
|
files = append(files,
|
||||||
|
assets.NewMemoryAssetTarget([]byte(defaultCNIConfig), constants.DefaultCNIConfigPath, "0644"),
|
||||||
|
assets.NewMemoryAssetTarget([]byte(defaultCNIConfig), constants.DefaultRktNetConfigPath, "0644"))
|
||||||
|
}
|
||||||
|
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, bin := range []string{"kubelet", "kubeadm"} {
|
for _, bin := range []string{"kubelet", "kubeadm"} {
|
||||||
bin := bin
|
bin := bin
|
||||||
|
@ -422,6 +436,12 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
|
||||||
return "", errors.Wrap(err, "generating extra component config for kubeadm")
|
return "", errors.Wrap(err, "generating extra component config for kubeadm")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case of no port assigned, use util.APIServerPort
|
||||||
|
nodePort := k8s.NodePort
|
||||||
|
if nodePort <= 0 {
|
||||||
|
nodePort = util.APIServerPort
|
||||||
|
}
|
||||||
|
|
||||||
opts := struct {
|
opts := struct {
|
||||||
CertDir string
|
CertDir string
|
||||||
ServiceCIDR string
|
ServiceCIDR string
|
||||||
|
@ -438,7 +458,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
|
||||||
CertDir: util.DefaultCertPath,
|
CertDir: util.DefaultCertPath,
|
||||||
ServiceCIDR: util.DefaultServiceCIDR,
|
ServiceCIDR: util.DefaultServiceCIDR,
|
||||||
AdvertiseAddress: k8s.NodeIP,
|
AdvertiseAddress: k8s.NodeIP,
|
||||||
APIServerPort: util.APIServerPort,
|
APIServerPort: nodePort,
|
||||||
KubernetesVersion: k8s.KubernetesVersion,
|
KubernetesVersion: k8s.KubernetesVersion,
|
||||||
EtcdDataDir: "/data/minikube", //TODO(r2d4): change to something else persisted
|
EtcdDataDir: "/data/minikube", //TODO(r2d4): change to something else persisted
|
||||||
NodeName: k8s.NodeName,
|
NodeName: k8s.NodeName,
|
||||||
|
|
|
@ -228,6 +228,32 @@ schedulerExtraArgs:
|
||||||
},
|
},
|
||||||
shouldErr: true,
|
shouldErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "custom api server port",
|
||||||
|
cfg: config.KubernetesConfig{
|
||||||
|
NodeIP: "192.168.1.100",
|
||||||
|
NodePort: 18443,
|
||||||
|
KubernetesVersion: "v1.10.0",
|
||||||
|
NodeName: "minikube",
|
||||||
|
},
|
||||||
|
expectedCfg: `apiVersion: kubeadm.k8s.io/v1alpha1
|
||||||
|
kind: MasterConfiguration
|
||||||
|
noTaintMaster: true
|
||||||
|
api:
|
||||||
|
advertiseAddress: 192.168.1.100
|
||||||
|
bindPort: 18443
|
||||||
|
controlPlaneEndpoint: localhost
|
||||||
|
kubernetesVersion: v1.10.0
|
||||||
|
certificatesDir: /var/lib/minikube/certs/
|
||||||
|
networking:
|
||||||
|
serviceSubnet: 10.96.0.0/12
|
||||||
|
etcd:
|
||||||
|
dataDir: /data/minikube
|
||||||
|
nodeName: minikube
|
||||||
|
apiServerExtraArgs:
|
||||||
|
admission-control: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota"
|
||||||
|
`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
@ -177,7 +177,7 @@ func restartKubeProxy(k8s config.KubernetesConfig) error {
|
||||||
APIServerPort int
|
APIServerPort int
|
||||||
}{
|
}{
|
||||||
AdvertiseAddress: k8s.NodeIP,
|
AdvertiseAddress: k8s.NodeIP,
|
||||||
APIServerPort: util.APIServerPort,
|
APIServerPort: k8s.NodePort,
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeconfig := bytes.Buffer{}
|
kubeconfig := bytes.Buffer{}
|
||||||
|
|
|
@ -145,7 +145,7 @@ func (s *SSHRunner) CombinedOutput(cmd string) (string, error) {
|
||||||
err = teeSSH(sess, cmd, &combined, &combined)
|
err = teeSSH(sess, cmd, &combined, &combined)
|
||||||
out := combined.b.String()
|
out := combined.b.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return out, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error)
|
||||||
return nil, errors.Wrap(err, "Error loading existing host. Please try running [minikube delete], then run [minikube start] again.")
|
return nil, errors.Wrap(err, "Error loading existing host. Please try running [minikube delete], then run [minikube start] again.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if h.Driver.DriverName() != config.VMDriver {
|
||||||
|
fmt.Printf("Skipping %s driver, existing host has %s driver.\n", config.VMDriver, h.Driver.DriverName())
|
||||||
|
}
|
||||||
|
|
||||||
s, err := h.Driver.GetState()
|
s, err := h.Driver.GetState()
|
||||||
glog.Infoln("Machine state: ", s)
|
glog.Infoln("Machine state: ", s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -195,6 +199,13 @@ Please consider switching to the hyperkit driver, which is intended to replace t
|
||||||
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver for more information.
|
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver for more information.
|
||||||
To disable this message, run [minikube config set WantShowDriverDeprecationNotification false]`)
|
To disable this message, run [minikube config set WantShowDriverDeprecationNotification false]`)
|
||||||
}
|
}
|
||||||
|
case "vmwarefusion":
|
||||||
|
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
||||||
|
fmt.Fprintln(os.Stderr, `WARNING: The vmwarefusion driver is now deprecated and support for it will be removed in a future release.
|
||||||
|
Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.
|
||||||
|
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#vmware-unified-driver for more information.
|
||||||
|
To disable this message, run [minikube config set WantShowDriverDeprecationNotification false]`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
_ "k8s.io/minikube/pkg/minikube/drivers/kvm2"
|
_ "k8s.io/minikube/pkg/minikube/drivers/kvm2"
|
||||||
_ "k8s.io/minikube/pkg/minikube/drivers/none"
|
_ "k8s.io/minikube/pkg/minikube/drivers/none"
|
||||||
_ "k8s.io/minikube/pkg/minikube/drivers/virtualbox"
|
_ "k8s.io/minikube/pkg/minikube/drivers/virtualbox"
|
||||||
|
_ "k8s.io/minikube/pkg/minikube/drivers/vmware"
|
||||||
_ "k8s.io/minikube/pkg/minikube/drivers/vmwarefusion"
|
_ "k8s.io/minikube/pkg/minikube/drivers/vmwarefusion"
|
||||||
_ "k8s.io/minikube/pkg/minikube/drivers/xhyve"
|
_ "k8s.io/minikube/pkg/minikube/drivers/xhyve"
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,6 +58,7 @@ type MachineConfig struct {
|
||||||
type KubernetesConfig struct {
|
type KubernetesConfig struct {
|
||||||
KubernetesVersion string
|
KubernetesVersion string
|
||||||
NodeIP string
|
NodeIP string
|
||||||
|
NodePort int
|
||||||
NodeName string
|
NodeName string
|
||||||
APIServerName string
|
APIServerName string
|
||||||
APIServerNames []string
|
APIServerNames []string
|
||||||
|
@ -71,4 +72,5 @@ type KubernetesConfig struct {
|
||||||
ExtraOptions util.ExtraOptionSlice
|
ExtraOptions util.ExtraOptionSlice
|
||||||
|
|
||||||
ShouldLoadCachedImages bool
|
ShouldLoadCachedImages bool
|
||||||
|
EnableDefaultCNI bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ var SupportedVMDrivers = [...]string{
|
||||||
"hyperv",
|
"hyperv",
|
||||||
"hyperkit",
|
"hyperkit",
|
||||||
"kvm2",
|
"kvm2",
|
||||||
|
"vmware",
|
||||||
"none",
|
"none",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,8 @@ const (
|
||||||
DefaultStatusFormat = `host: {{.Host}}
|
DefaultStatusFormat = `host: {{.Host}}
|
||||||
kubelet: {{.Kubelet}}
|
kubelet: {{.Kubelet}}
|
||||||
apiserver: {{.ApiServer}}
|
apiserver: {{.ApiServer}}
|
||||||
kubectl: {{.Kubeconfig}}`
|
kubectl: {{.Kubeconfig}}
|
||||||
|
`
|
||||||
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
|
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
|
||||||
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
|
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
|
||||||
DefaultCacheListFormat = "{{.CacheImage}}\n"
|
DefaultCacheListFormat = "{{.CacheImage}}\n"
|
||||||
|
@ -127,7 +129,7 @@ kubectl: {{.Kubeconfig}}`
|
||||||
var DefaultIsoUrl = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetIsoPath(), minikubeVersion.GetIsoVersion())
|
var DefaultIsoUrl = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetIsoPath(), minikubeVersion.GetIsoVersion())
|
||||||
var DefaultIsoShaUrl = DefaultIsoUrl + ShaSuffix
|
var DefaultIsoShaUrl = DefaultIsoUrl + ShaSuffix
|
||||||
|
|
||||||
var DefaultKubernetesVersion = "v1.12.4"
|
var DefaultKubernetesVersion = "v1.13.2"
|
||||||
|
|
||||||
var ConfigFilePath = MakeMiniPath("config")
|
var ConfigFilePath = MakeMiniPath("config")
|
||||||
var ConfigFile = MakeMiniPath("config", "config.json")
|
var ConfigFile = MakeMiniPath("config", "config.json")
|
||||||
|
@ -146,9 +148,11 @@ const AddonsPath = "/etc/kubernetes/addons"
|
||||||
const FilesPath = "/files"
|
const FilesPath = "/files"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KubeletServiceFile = "/lib/systemd/system/kubelet.service"
|
KubeletServiceFile = "/lib/systemd/system/kubelet.service"
|
||||||
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
|
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
|
||||||
KubeadmConfigFile = "/var/lib/kubeadm.yaml"
|
KubeadmConfigFile = "/var/lib/kubeadm.yaml"
|
||||||
|
DefaultCNIConfigPath = "/etc/cni/net.d/k8s.conf"
|
||||||
|
DefaultRktNetConfigPath = "/etc/rkt/net.d/k8s.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Preflights = []string{
|
var Preflights = []string{
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package vmware
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package vmware
|
||||||
|
|
||||||
|
import (
|
||||||
|
vmwcfg "github.com/machine-drivers/docker-machine-driver-vmware/pkg/drivers/vmware/config"
|
||||||
|
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
|
"k8s.io/minikube/pkg/minikube/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registry.Register(registry.DriverDef{
|
||||||
|
Name: "vmware",
|
||||||
|
Builtin: false,
|
||||||
|
ConfigCreator: createVMwareHost,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func createVMwareHost(config cfg.MachineConfig) interface{} {
|
||||||
|
d := vmwcfg.NewConfig(cfg.GetMachineName(), constants.GetMinipath())
|
||||||
|
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||||
|
d.Memory = config.Memory
|
||||||
|
d.CPU = config.CPUs
|
||||||
|
d.DiskSize = config.DiskSize
|
||||||
|
|
||||||
|
// TODO(frapposelli): push these defaults upstream to fixup this driver
|
||||||
|
d.SSHPort = 22
|
||||||
|
d.ISO = d.ResolveStorePath("boot2docker.iso")
|
||||||
|
return d
|
||||||
|
}
|
|
@ -144,7 +144,7 @@ func hasWindowsDriveLetter(s string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
drive := s[:3]
|
drive := s[:3]
|
||||||
for _, b := range "CDEFGHIJKLMNOPQRSTUVWXYZAB" {
|
for _, b := range "CDEFGHIJKLMNOPQRSTUVWXYZABcdefghijklmnopqrstuvwxyzab" {
|
||||||
if d := string(b) + ":"; drive == d+`\` || drive == d+`/` {
|
if d := string(b) + ":"; drive == d+`\` || drive == d+`/` {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -160,9 +160,6 @@ func replaceWinDriveLetterToVolumeName(s string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
path := vname + s[3:]
|
path := vname + s[3:]
|
||||||
if _, err := os.Stat(filepath.Dir(path)); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,28 @@ limitations under the License.
|
||||||
package storageclass
|
package storageclass
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"k8s.io/api/storage/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func annotateDefaultStorageClass(client *kubernetes.Clientset, class *v1.StorageClass, enable bool) error {
|
||||||
|
isDefault := strconv.FormatBool(enable)
|
||||||
|
|
||||||
|
metav1.SetMetaDataAnnotation(&class.ObjectMeta, "storageclass.beta.kubernetes.io/is-default-class", isDefault)
|
||||||
|
_, err := client.Storage().StorageClasses().Update(class)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// DisableDefaultStorageClass disables the default storage class provisioner
|
// DisableDefaultStorageClass disables the default storage class provisioner
|
||||||
// The addon-manager and kubectl apply cannot delete storageclasses
|
// The addon-manager and kubectl apply cannot delete storageclasses
|
||||||
func DisableDefaultStorageClass() error {
|
func DisableDefaultStorageClass(class string) error {
|
||||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||||
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
|
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
|
||||||
config, err := kubeConfig.ClientConfig()
|
config, err := kubeConfig.ClientConfig()
|
||||||
|
@ -39,9 +50,47 @@ func DisableDefaultStorageClass() error {
|
||||||
return errors.Wrap(err, "Error creating new client from kubeConfig.ClientConfig()")
|
return errors.Wrap(err, "Error creating new client from kubeConfig.ClientConfig()")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.Storage().StorageClasses().Delete(constants.DefaultStorageClassProvisioner, &metav1.DeleteOptions{})
|
sc, err := client.Storage().StorageClasses().Get(class, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Error deleting default storage class %s", constants.DefaultStorageClassProvisioner)
|
return errors.Wrapf(err, "Error getting storage class %s", class)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = annotateDefaultStorageClass(client, sc, false)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Error marking storage class %s as non-default", class)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefaultStorageClass makes sure onlt the class with @name is marked as
|
||||||
|
// default.
|
||||||
|
func SetDefaultStorageClass(name string) error {
|
||||||
|
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||||
|
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
|
||||||
|
config, err := kubeConfig.ClientConfig()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Error creating kubeConfig")
|
||||||
|
}
|
||||||
|
client, err := kubernetes.NewForConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Error creating new client from kubeConfig.ClientConfig()")
|
||||||
|
}
|
||||||
|
|
||||||
|
scList, err := client.Storage().StorageClasses().List(metav1.ListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Error listing StorageClasses")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sc := range scList.Items {
|
||||||
|
err = annotateDefaultStorageClass(client, &sc, sc.Name == name)
|
||||||
|
if err != nil {
|
||||||
|
isDefault := "non-default"
|
||||||
|
if sc.Name == name {
|
||||||
|
isDefault = "default"
|
||||||
|
}
|
||||||
|
return errors.Wrapf(err, "Error while marking storage class %s as %s", sc.Name, isDefault)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -249,12 +249,16 @@ func UpdateKubeconfigIP(ip net.IP, filename string, machineName string) (bool, e
|
||||||
if kip.Equal(ip) {
|
if kip.Equal(ip) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
kport, err := getPortFromKubeConfig(filename, machineName)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
con, err := ReadConfigOrNew(filename)
|
con, err := ReadConfigOrNew(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "Error getting kubeconfig status")
|
return false, errors.Wrap(err, "Error getting kubeconfig status")
|
||||||
}
|
}
|
||||||
// Safe to lookup server because if field non-existent getIPFromKubeconfig would have given an error
|
// Safe to lookup server because if field non-existent getIPFromKubeconfig would have given an error
|
||||||
con.Clusters[machineName].Server = "https://" + ip.String() + ":" + strconv.Itoa(util.APIServerPort)
|
con.Clusters[machineName].Server = "https://" + ip.String() + ":" + strconv.Itoa(kport)
|
||||||
err = WriteConfig(con, filename)
|
err = WriteConfig(con, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -284,3 +288,25 @@ func getIPFromKubeConfig(filename, machineName string) (net.IP, error) {
|
||||||
ip := net.ParseIP(kip)
|
ip := net.ParseIP(kip)
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified
|
||||||
|
func getPortFromKubeConfig(filename, machineName string) (int, error) {
|
||||||
|
con, err := ReadConfigOrNew(filename)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.Wrap(err, "Error getting kubeconfig status")
|
||||||
|
}
|
||||||
|
cluster, ok := con.Clusters[machineName]
|
||||||
|
if !ok {
|
||||||
|
return 0, errors.Errorf("Kubeconfig does not have a record of the machine cluster")
|
||||||
|
}
|
||||||
|
kurl, err := url.Parse(cluster.Server)
|
||||||
|
if err != nil {
|
||||||
|
return util.APIServerPort, nil
|
||||||
|
}
|
||||||
|
_, kport, err := net.SplitHostPort(kurl.Host)
|
||||||
|
if err != nil {
|
||||||
|
return util.APIServerPort, nil
|
||||||
|
}
|
||||||
|
port, err := strconv.Atoi(kport)
|
||||||
|
return port, err
|
||||||
|
}
|
||||||
|
|
2
test.sh
2
test.sh
|
@ -34,7 +34,7 @@ echo "Running go tests..."
|
||||||
cd ${GOPATH}/src/${REPO_PATH}
|
cd ${GOPATH}/src/${REPO_PATH}
|
||||||
rm -f out/$COV_FILE || true
|
rm -f out/$COV_FILE || true
|
||||||
echo "mode: count" > out/$COV_FILE
|
echo "mode: count" > out/$COV_FILE
|
||||||
for pkg in $(go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{end}}' ./...); do
|
for pkg in $(go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{end}}' ./cmd/... ./pkg/...); do
|
||||||
go test -tags "container_image_ostree_stub containers_image_openpgp" -v $pkg -covermode=count -coverprofile=out/$COV_TMP_FILE
|
go test -tags "container_image_ostree_stub containers_image_openpgp" -v $pkg -covermode=count -coverprofile=out/$COV_TMP_FILE
|
||||||
# tail -n +2 skips the first line of the file
|
# tail -n +2 skips the first line of the file
|
||||||
# for coverprofile the first line is the `mode: count` line which we only want once in our file
|
# for coverprofile the first line is the `mode: count` line which we only want once in our file
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestISO(t *testing.T) {
|
||||||
|
|
||||||
minikubeRunner := NewMinikubeRunner(t)
|
minikubeRunner := NewMinikubeRunner(t)
|
||||||
|
|
||||||
minikubeRunner.RunCommand("delete", true)
|
minikubeRunner.RunCommand("delete", false)
|
||||||
minikubeRunner.Start()
|
minikubeRunner.Start()
|
||||||
|
|
||||||
t.Run("permissions", testMountPermissions)
|
t.Run("permissions", testMountPermissions)
|
||||||
|
|
|
@ -44,10 +44,6 @@ func TestPersistence(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
verify := func(t *testing.T) {
|
verify := func(t *testing.T) {
|
||||||
if err := util.WaitForDashboardRunning(t); err != nil {
|
|
||||||
t.Fatalf("waiting for dashboard to be up: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := util.WaitForBusyboxRunning(t, "default"); err != nil {
|
if err := util.WaitForBusyboxRunning(t, "default"); err != nil {
|
||||||
t.Fatalf("waiting for busybox to be up: %v", err)
|
t.Fatalf("waiting for busybox to be up: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (m *MinikubeRunner) Run(cmd string) error {
|
||||||
func (m *MinikubeRunner) Copy(f assets.CopyableFile) error {
|
func (m *MinikubeRunner) Copy(f assets.CopyableFile) error {
|
||||||
path, _ := filepath.Abs(m.BinaryPath)
|
path, _ := filepath.Abs(m.BinaryPath)
|
||||||
cmd := exec.Command("/bin/bash", "-c", path, "ssh", "--", fmt.Sprintf("cat >> %s", filepath.Join(f.GetTargetDir(), f.GetTargetName())))
|
cmd := exec.Command("/bin/bash", "-c", path, "ssh", "--", fmt.Sprintf("cat >> %s", filepath.Join(f.GetTargetDir(), f.GetTargetName())))
|
||||||
Logf("Running: %s", cmd)
|
Logf("Running: %s", cmd.Args)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,17 @@ func (m *MinikubeRunner) RunDaemon(command string) (*exec.Cmd, *bufio.Reader) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.T.Fatalf("stdout pipe failed: %s %v", command, err)
|
m.T.Fatalf("stdout pipe failed: %s %v", command, err)
|
||||||
}
|
}
|
||||||
|
stderrPipe, err := cmd.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
m.T.Fatalf("stderr pipe failed: %s %v", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var errB bytes.Buffer
|
||||||
|
go func() {
|
||||||
|
if err := commonutil.TeePrefix(commonutil.ErrPrefix, stderrPipe, &errB, Logf); err != nil {
|
||||||
|
m.T.Logf("tee: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -174,7 +185,7 @@ func (m *MinikubeRunner) SSH(command string) (string, error) {
|
||||||
func (m *MinikubeRunner) Start() {
|
func (m *MinikubeRunner) Start() {
|
||||||
switch r := m.Runtime; r {
|
switch r := m.Runtime; r {
|
||||||
case constants.ContainerdRuntime:
|
case constants.ContainerdRuntime:
|
||||||
containerdFlags := "--container-runtime=containerd --network-plugin=cni --docker-opt containerd=/var/run/containerd/containerd.sock"
|
containerdFlags := "--container-runtime=containerd --network-plugin=cni --enable-default-cni --docker-opt containerd=/var/run/containerd/containerd.sock"
|
||||||
m.RunCommand(fmt.Sprintf("start %s %s %s --alsologtostderr --v=5", m.StartArgs, m.Args, containerdFlags), true)
|
m.RunCommand(fmt.Sprintf("start %s %s %s --alsologtostderr --v=5", m.StartArgs, m.Args, containerdFlags), true)
|
||||||
default:
|
default:
|
||||||
m.RunCommand(fmt.Sprintf("start %s %s --alsologtostderr --v=5", m.StartArgs, m.Args), true)
|
m.RunCommand(fmt.Sprintf("start %s %s --alsologtostderr --v=5", m.StartArgs, m.Args), true)
|
||||||
|
@ -295,18 +306,6 @@ func WaitForBusyboxRunning(t *testing.T, namespace string) error {
|
||||||
return commonutil.WaitForPodsWithLabelRunning(client, namespace, selector)
|
return commonutil.WaitForPodsWithLabelRunning(client, namespace, selector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WaitForDashboardRunning(t *testing.T) error {
|
|
||||||
client, err := commonutil.GetClient()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "getting kubernetes client")
|
|
||||||
}
|
|
||||||
if err := commonutil.WaitForDeploymentToStabilize(client, "kube-system", "kubernetes-dashboard", time.Minute*10); err != nil {
|
|
||||||
return errors.Wrap(err, "waiting for dashboard deployment to stabilize")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func WaitForIngressControllerRunning(t *testing.T) error {
|
func WaitForIngressControllerRunning(t *testing.T) error {
|
||||||
client, err := commonutil.GetClient()
|
client, err := commonutil.GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,216 @@
|
||||||
|
# This is the official list of go-github authors for copyright purposes.
|
||||||
|
#
|
||||||
|
# This does not necessarily list everyone who has contributed code, since in
|
||||||
|
# some cases, their employer may be the copyright holder. To see the full list
|
||||||
|
# of contributors, see the revision history in source control or
|
||||||
|
# https://github.com/google/go-github/graphs/contributors.
|
||||||
|
#
|
||||||
|
# Authors who wish to be recognized in this file should add themselves (or
|
||||||
|
# their employer, as appropriate).
|
||||||
|
|
||||||
|
178inaba <masahiro.furudate@gmail.com>
|
||||||
|
Abhinav Gupta <mail@abhinavg.net>
|
||||||
|
Ahmed Hagy <a.akram93@gmail.com>
|
||||||
|
Ainsley Chong <ainsley.chong@gmail.com>
|
||||||
|
Akeda Bagus <akeda@x-team.com>
|
||||||
|
Akhil Mohan <akhilerm@gmail.com>
|
||||||
|
Alec Thomas <alec@swapoff.org>
|
||||||
|
Aleks Clark <aleks.clark@gmail.com>
|
||||||
|
Alex Bramley <a.bramley@gmail.com>
|
||||||
|
Alexander Harkness <me@bearbin.net>
|
||||||
|
Allen Sun <shlallen1990@gmail.com>
|
||||||
|
Amey Sakhadeo <me@ameyms.com>
|
||||||
|
Andreas Garnæs <https://github.com/andreas>
|
||||||
|
Andrew Ryabchun <aryabchun@mail.ua>
|
||||||
|
Andy Grunwald <andygrunwald@gmail.com>
|
||||||
|
Andy Hume <andyhume@gmail.com>
|
||||||
|
Andy Lindeman <andy@lindeman.io>
|
||||||
|
Anshuman Bhartiya <anshuman.bhartiya@gmail.com>
|
||||||
|
Antoine <antoine.tu@mail.mcgill.ca>
|
||||||
|
Antoine Pelisse <apelisse@gmail.com>
|
||||||
|
Anubha Kushwaha <anubha_bt2k14@dtu.ac.in>
|
||||||
|
appilon <apilon@hashicorp.com>
|
||||||
|
Aravind <aravindkp@outlook.in>
|
||||||
|
Arıl Bozoluk <arilbozoluk@hotmail.com>
|
||||||
|
Austin Dizzy <dizzy@wow.com>
|
||||||
|
Ben Batha <bhbatha@gmail.com>
|
||||||
|
Beshr Kayali <beshrkayali@gmail.com>
|
||||||
|
Beyang Liu <beyang.liu@gmail.com>
|
||||||
|
Billy Lynch <wlynch92@gmail.com>
|
||||||
|
Björn Häuser <b.haeuser@rebuy.de>
|
||||||
|
Brad Harris <bmharris@gmail.com>
|
||||||
|
Brad Moylan <moylan.brad@gmail.com>
|
||||||
|
Bradley Falzon <brad@teambrad.net>
|
||||||
|
Brandon Cook <phylake@gmail.com>
|
||||||
|
Brian Egizi <brian@mojotech.com>
|
||||||
|
Bryan Boreham <bryan@weave.works>
|
||||||
|
Cami Diez <diezcami@gmail.com>
|
||||||
|
Carlos Alexandro Becker <caarlos0@gmail.com>
|
||||||
|
chandresh-pancholi <chandreshpancholi007@gmail.com>
|
||||||
|
Charles Fenwick Elliott <Charles@FenwickElliott.io>
|
||||||
|
Charlie Yan <charlieyan08@gmail.com>
|
||||||
|
Chris King <chriskingnet@gmail.com>
|
||||||
|
Chris Roche <chris@vsco.co>
|
||||||
|
Chris Schaefer <chris@dtzq.com>
|
||||||
|
Christoph Sassenberg <defsprite@gmail.com>
|
||||||
|
Colin Misare <github.com/cmisare>
|
||||||
|
Craig Peterson <cpeterson@stackoverflow.com>
|
||||||
|
Cristian Maglie <c.maglie@bug.st>
|
||||||
|
Daehyeok Mun <daehyeok@gmail.com>
|
||||||
|
Daniel Leavitt <daniel.leavitt@gmail.com>
|
||||||
|
Daniel Nilsson <daniel.nilsson1989@gmail.com>
|
||||||
|
Dave Du Cros <davidducros@gmail.com>
|
||||||
|
Dave Henderson <dhenderson@gmail.com>
|
||||||
|
David Deng <daviddengcn@gmail.com>
|
||||||
|
David Jannotta <djannotta@gmail.com>
|
||||||
|
Davide Zipeto <dawez1@gmail.com>
|
||||||
|
Dennis Webb <dennis@bluesentryit.com>
|
||||||
|
Dhi Aurrahman <diorahman@rockybars.com>
|
||||||
|
Diego Lapiduz <diego.lapiduz@cfpb.gov>
|
||||||
|
Dmitri Shuralyov <shurcooL@gmail.com>
|
||||||
|
dmnlk <seikima2demon@gmail.com>
|
||||||
|
Don Petersen <don@donpetersen.net>
|
||||||
|
Doug Turner <doug.turner@gmail.com>
|
||||||
|
Drew Fradette <drew.fradette@gmail.com>
|
||||||
|
Eli Uriegas <seemethere101@gmail.com>
|
||||||
|
Elliott Beach <elliott2.71828@gmail.com>
|
||||||
|
Emerson Wood <emersonwood94@gmail.com>
|
||||||
|
eperm <staffordworrell@gmail.com>
|
||||||
|
erwinvaneyk <erwinvaneyk@gmail.com>
|
||||||
|
Fabrice <fabrice.vaillant@student.ecp.fr>
|
||||||
|
Filippo Valsorda <hi@filippo.io>
|
||||||
|
Florian Forster <ff@octo.it>
|
||||||
|
Francesc Gil <xescugil@gmail.com>
|
||||||
|
Francis <hello@francismakes.com>
|
||||||
|
Fredrik Jönsson <fredrik.jonsson@izettle.com>
|
||||||
|
Garrett Squire <garrettsquire@gmail.com>
|
||||||
|
George Kontridze <george.kontridze@gmail.com>
|
||||||
|
Georgy Buranov <gburanov@gmail.com>
|
||||||
|
Gnahz <p@oath.pl>
|
||||||
|
Google Inc.
|
||||||
|
Grachev Mikhail <work@mgrachev.com>
|
||||||
|
griffin_stewie <panterathefamilyguy@gmail.com>
|
||||||
|
Guillaume Jacquet <guillaume.jacquet@gmail.com>
|
||||||
|
Guz Alexander <kalimatas@gmail.com>
|
||||||
|
Guðmundur Bjarni Ólafsson <gudmundur@github.com>
|
||||||
|
Hanno Hecker <hanno.hecker@zalando.de>
|
||||||
|
Hari haran <hariharan.uno@gmail.com>
|
||||||
|
haya14busa <hayabusa1419@gmail.com>
|
||||||
|
Huy Tr <kingbazoka@gmail.com>
|
||||||
|
huydx <doxuanhuy@gmail.com>
|
||||||
|
i2bskn <i2bskn@gmail.com>
|
||||||
|
Isao Jonas <isao.jonas@gmail.com>
|
||||||
|
isqua <isqua@isqua.ru>
|
||||||
|
Jameel Haffejee <RC1140@republiccommandos.co.za>
|
||||||
|
Jan Kosecki <jan.kosecki91@gmail.com>
|
||||||
|
Javier Campanini <jcampanini@palantir.com>
|
||||||
|
Jeremy Morris <jeremylevanmorris@gmail.com>
|
||||||
|
Jesse Newland <jesse@jnewland.com>
|
||||||
|
Jihoon Chung <j.c@navercorp.com>
|
||||||
|
Jimmi Dyson <jimmidyson@gmail.com>
|
||||||
|
Joan Saum <joan.saum@epitech.eu>
|
||||||
|
Joe Tsai <joetsai@digital-static.net>
|
||||||
|
John Barton <jrbarton@gmail.com>
|
||||||
|
John Engelman <john.r.engelman@gmail.com>
|
||||||
|
JP Phillips <jonphill9@gmail.com>
|
||||||
|
jpbelanger-mtl <jp.belanger@gmail.com>
|
||||||
|
Juan Basso <jrbasso@gmail.com>
|
||||||
|
Julien Garcia Gonzalez <garciagonzalez.julien@gmail.com>
|
||||||
|
Julien Rostand <jrostand@users.noreply.github.com>
|
||||||
|
Justin Abrahms <justin@abrah.ms>
|
||||||
|
Jusung Lee <e.jusunglee@gmail.com>
|
||||||
|
jzhoucliqr <jzhou@cliqr.com>
|
||||||
|
Katrina Owen <kytrinyx@github.com>
|
||||||
|
Kautilya Tripathi < tripathi.kautilya@gmail.com>
|
||||||
|
Keita Urashima <ursm@ursm.jp>
|
||||||
|
Kevin Burke <kev@inburke.com>
|
||||||
|
Konrad Malawski <konrad.malawski@project13.pl>
|
||||||
|
Kookheon Kwon <kucuny@gmail.com>
|
||||||
|
Krzysztof Kowalczyk <kkowalczyk@gmail.com>
|
||||||
|
Kshitij Saraogi <KshitijSaraogi@gmail.com>
|
||||||
|
kyokomi <kyoko1220adword@gmail.com>
|
||||||
|
Lucas Alcantara <lucasalcantaraf@gmail.com>
|
||||||
|
Luke Evers <me@lukevers.com>
|
||||||
|
Luke Kysow <lkysow@gmail.com>
|
||||||
|
Luke Roberts <email@luke-roberts.co.uk>
|
||||||
|
Luke Young <luke@hydrantlabs.org>
|
||||||
|
Maksim Zhylinski <uzzable@gmail.com>
|
||||||
|
Martin-Louis Bright <mlbright@gmail.com>
|
||||||
|
Marwan Sulaiman <marwan.sameer@gmail.com>
|
||||||
|
Mat Geist <matgeist@gmail.com>
|
||||||
|
Matt <alpmatthew@gmail.com>
|
||||||
|
Matt Brender <mjbrender@gmail.com>
|
||||||
|
Matt Gaunt <matt@gauntface.co.uk>
|
||||||
|
Matt Landis <landis.matt@gmail.com>
|
||||||
|
Maxime Bury <maxime.bury@gmail.com>
|
||||||
|
Michael Spiegel <michael.m.spiegel@gmail.com>
|
||||||
|
Michael Tiller <michael.tiller@gmail.com>
|
||||||
|
Michał Glapa <michal.glapa@gmail.com>
|
||||||
|
Nathan VanBenschoten <nvanbenschoten@gmail.com>
|
||||||
|
Navaneeth Suresh <navaneeths1998@gmail.com>
|
||||||
|
Neil O'Toole <neilotoole@apache.org>
|
||||||
|
Nick Miyake <nmiyake@palantir.com>
|
||||||
|
Nick Spragg <nick.spragg@bbc.co.uk>
|
||||||
|
Nikhita Raghunath <nikitaraghunath@gmail.com>
|
||||||
|
Noah Zoschke <noah+sso2@convox.com>
|
||||||
|
ns-cweber <cweber@narrativescience.com>
|
||||||
|
Oleg Kovalov <iamolegkovalov@gmail.com>
|
||||||
|
Ondřej Kupka <ondra.cap@gmail.com>
|
||||||
|
Palash Nigam <npalash25@gmail.com>
|
||||||
|
Panagiotis Moustafellos <pmoust@gmail.com>
|
||||||
|
Parham Alvani <parham.alvani@gmail.com>
|
||||||
|
Parker Moore <parkrmoore@gmail.com>
|
||||||
|
parkhyukjun89 <park.hyukjun89@gmail.com>
|
||||||
|
Pavel Shtanko <pavel.shtanko@gmail.com>
|
||||||
|
Pete Wagner <thepwagner@github.com>
|
||||||
|
Petr Shevtsov <petr.shevtsov@gmail.com>
|
||||||
|
Pierre Carrier <pierre@meteor.com>
|
||||||
|
Piotr Zurek <p.zurek@gmail.com>
|
||||||
|
Quinn Slack <qslack@qslack.com>
|
||||||
|
Rackspace US, Inc.
|
||||||
|
Radek Simko <radek.simko@gmail.com>
|
||||||
|
Radliński Ignacy <radlinsk@student.agh.edu.pl>
|
||||||
|
Rajendra arora <rajendraarora16@yahoo.com>
|
||||||
|
RaviTeja Pothana <ravi-teja@live.com>
|
||||||
|
rc1140 <jameel@republiccommandos.co.za>
|
||||||
|
Red Hat, Inc.
|
||||||
|
Rob Figueiredo <robfig@yext.com>
|
||||||
|
Rohit Upadhyay <urohit011@gmail.com>
|
||||||
|
Ronak Jain <ronakjain@outlook.in>
|
||||||
|
Ruben Vereecken <rubenvereecken@gmail.com>
|
||||||
|
Ryan Lower <rpjlower@gmail.com>
|
||||||
|
Sahil Dua <sahildua2305@gmail.com>
|
||||||
|
saisi <saisi@users.noreply.github.com>
|
||||||
|
Sam Minnée <sam@silverstripe.com>
|
||||||
|
Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
|
||||||
|
Sander van Harmelen <svanharmelen@schubergphilis.com>
|
||||||
|
Sanket Payghan <sanket.payghan8@gmail.com>
|
||||||
|
Sarasa Kisaragi <lingsamuelgrace@gmail.com>
|
||||||
|
Sean Wang <sean@decrypted.org>
|
||||||
|
Sebastian Mandrean <sebastian.mandrean@gmail.com>
|
||||||
|
Sebastian Mæland Pedersen <sem.pedersen@stud.uis.no>
|
||||||
|
Sevki <s@sevki.org>
|
||||||
|
Shagun Khemka <shagun.khemka60@gmail.com>
|
||||||
|
shakeelrao <shakeelrao79@gmail.com>
|
||||||
|
Shawn Catanzarite <me@shawncatz.com>
|
||||||
|
Shawn Smith <shawnpsmith@gmail.com>
|
||||||
|
sona-tar <sona.zip@gmail.com>
|
||||||
|
SoundCloud, Ltd.
|
||||||
|
Stian Eikeland <stian@eikeland.se>
|
||||||
|
Tasya Aditya Rukmana <tadityar@gmail.com>
|
||||||
|
Thomas Bruyelle <thomas.bruyelle@gmail.com>
|
||||||
|
Timothée Peignier <timothee.peignier@tryphon.org>
|
||||||
|
Trey Tacon <ttacon@gmail.com>
|
||||||
|
ttacon <ttacon@gmail.com>
|
||||||
|
Varadarajan Aravamudhan <varadaraajan@gmail.com>
|
||||||
|
Victor Castell <victor@victorcastell.com>
|
||||||
|
Victor Vrantchan <vrancean+github@gmail.com>
|
||||||
|
Vlad Ungureanu <vladu@palantir.com>
|
||||||
|
Will Maier <wcmaier@gmail.com>
|
||||||
|
William Bailey <mail@williambailey.org.uk>
|
||||||
|
xibz <impactbchang@gmail.com>
|
||||||
|
Yann Malet <yann.malet@gmail.com>
|
||||||
|
Yannick Utard <yannickutard@gmail.com>
|
||||||
|
Yicheng Qin <qycqycqycqycqyc@gmail.com>
|
||||||
|
Yumikiyo Osanai <yumios.art@gmail.com>
|
||||||
|
Zach Latta <zach@zachlatta.com>
|
|
@ -0,0 +1,27 @@
|
||||||
|
Copyright (c) 2013 The go-github 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 Google Inc. 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
|
||||||
|
OWNER 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.
|
|
@ -0,0 +1,69 @@
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
// ActivityService handles communication with the activity related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/
|
||||||
|
type ActivityService service
|
||||||
|
|
||||||
|
// FeedLink represents a link to a related resource.
|
||||||
|
type FeedLink struct {
|
||||||
|
HRef *string `json:"href,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Feeds represents timeline resources in Atom format.
|
||||||
|
type Feeds struct {
|
||||||
|
TimelineURL *string `json:"timeline_url,omitempty"`
|
||||||
|
UserURL *string `json:"user_url,omitempty"`
|
||||||
|
CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"`
|
||||||
|
CurrentUserURL *string `json:"current_user_url,omitempty"`
|
||||||
|
CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"`
|
||||||
|
CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"`
|
||||||
|
CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"`
|
||||||
|
Links *struct {
|
||||||
|
Timeline *FeedLink `json:"timeline,omitempty"`
|
||||||
|
User *FeedLink `json:"user,omitempty"`
|
||||||
|
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
|
||||||
|
CurrentUser *FeedLink `json:"current_user,omitempty"`
|
||||||
|
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
|
||||||
|
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
|
||||||
|
CurrentUserOrganizations []FeedLink `json:"current_user_organizations,omitempty"`
|
||||||
|
} `json:"_links,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFeeds lists all the feeds available to the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub provides several timeline resources in Atom format:
|
||||||
|
// Timeline: The GitHub global public timeline
|
||||||
|
// User: The public timeline for any user, using URI template
|
||||||
|
// Current user public: The public timeline for the authenticated user
|
||||||
|
// Current user: The private timeline for the authenticated user
|
||||||
|
// Current user actor: The private timeline for activity created by the
|
||||||
|
// authenticated user
|
||||||
|
// Current user organizations: The private timeline for the organizations
|
||||||
|
// the authenticated user is a member of.
|
||||||
|
//
|
||||||
|
// Note: Private feeds are only returned when authenticating via Basic Auth
|
||||||
|
// since current feed URIs use the older, non revocable auth tokens.
|
||||||
|
func (s *ActivityService) ListFeeds(ctx context.Context) (*Feeds, *Response, error) {
|
||||||
|
req, err := s.client.NewRequest("GET", "feeds", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
f := &Feeds{}
|
||||||
|
resp, err := s.client.Do(ctx, req, f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,215 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListEvents drinks from the firehose of all public events across GitHub.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events
|
||||||
|
func (s *ActivityService) ListEvents(ctx context.Context, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
u, err := addOptions("events", opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepositoryEvents lists events for a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-repository-events
|
||||||
|
func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueEventsForRepository lists issue events for a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
|
||||||
|
func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*IssueEvent
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEventsForRepoNetwork lists public events for a network of repositories.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
|
||||||
|
func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
u := fmt.Sprintf("networks/%v/%v/events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEventsForOrganization lists public events for an organization.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
|
||||||
|
func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org string, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/events", 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 events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEventsPerformedByUser lists the events performed by a user. If publicOnly is
|
||||||
|
// true, only public events will be returned.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
|
||||||
|
func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if publicOnly {
|
||||||
|
u = fmt.Sprintf("users/%v/events/public", user)
|
||||||
|
} else {
|
||||||
|
u = fmt.Sprintf("users/%v/events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEventsReceivedByUser lists the events received by a user. If publicOnly is
|
||||||
|
// true, only public events will be returned.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
|
||||||
|
func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if publicOnly {
|
||||||
|
u = fmt.Sprintf("users/%v/received_events/public", user)
|
||||||
|
} else {
|
||||||
|
u = fmt.Sprintf("users/%v/received_events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListUserEventsForOrganization provides the user’s organization dashboard. You
|
||||||
|
// must be authenticated as the user to view this.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-for-an-organization
|
||||||
|
func (s *ActivityService) ListUserEventsForOrganization(ctx context.Context, org, user string, opt *ListOptions) ([]*Event, *Response, error) {
|
||||||
|
u := fmt.Sprintf("users/%v/events/orgs/%v", user, 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 events []*Event
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
223
vendor/github.com/google/go-github/github/activity_notifications.go
generated
vendored
Normal file
223
vendor/github.com/google/go-github/github/activity_notifications.go
generated
vendored
Normal file
|
@ -0,0 +1,223 @@
|
||||||
|
// Copyright 2014 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notification identifies a GitHub notification for a user.
|
||||||
|
type Notification struct {
|
||||||
|
ID *string `json:"id,omitempty"`
|
||||||
|
Repository *Repository `json:"repository,omitempty"`
|
||||||
|
Subject *NotificationSubject `json:"subject,omitempty"`
|
||||||
|
|
||||||
|
// Reason identifies the event that triggered the notification.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#notification-reasons
|
||||||
|
Reason *string `json:"reason,omitempty"`
|
||||||
|
|
||||||
|
Unread *bool `json:"unread,omitempty"`
|
||||||
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||||
|
LastReadAt *time.Time `json:"last_read_at,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationSubject identifies the subject of a notification.
|
||||||
|
type NotificationSubject struct {
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
LatestCommentURL *string `json:"latest_comment_url,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationListOptions specifies the optional parameters to the
|
||||||
|
// ActivityService.ListNotifications method.
|
||||||
|
type NotificationListOptions struct {
|
||||||
|
All bool `url:"all,omitempty"`
|
||||||
|
Participating bool `url:"participating,omitempty"`
|
||||||
|
Since time.Time `url:"since,omitempty"`
|
||||||
|
Before time.Time `url:"before,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNotifications lists all notifications for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#list-your-notifications
|
||||||
|
func (s *ActivityService) ListNotifications(ctx context.Context, opt *NotificationListOptions) ([]*Notification, *Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications")
|
||||||
|
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 notifications []*Notification
|
||||||
|
resp, err := s.client.Do(ctx, req, ¬ifications)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return notifications, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepositoryNotifications lists all notifications in a given repository
|
||||||
|
// for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
|
||||||
|
func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner, repo string, opt *NotificationListOptions) ([]*Notification, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/notifications", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var notifications []*Notification
|
||||||
|
resp, err := s.client.Do(ctx, req, ¬ifications)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return notifications, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type markReadOptions struct {
|
||||||
|
LastReadAt time.Time `json:"last_read_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkNotificationsRead marks all notifications up to lastRead as read.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-as-read
|
||||||
|
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) {
|
||||||
|
opts := &markReadOptions{
|
||||||
|
LastReadAt: lastRead,
|
||||||
|
}
|
||||||
|
req, err := s.client.NewRequest("PUT", "notifications", opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkRepositoryNotificationsRead marks all notifications up to lastRead in
|
||||||
|
// the specified repository as read.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
|
||||||
|
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) {
|
||||||
|
opts := &markReadOptions{
|
||||||
|
LastReadAt: lastRead,
|
||||||
|
}
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/notifications", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("PUT", u, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetThread gets the specified notification thread.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#view-a-single-thread
|
||||||
|
func (s *ActivityService) GetThread(ctx context.Context, id string) (*Notification, *Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications/threads/%v", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
notification := new(Notification)
|
||||||
|
resp, err := s.client.Do(ctx, req, notification)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return notification, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkThreadRead marks the specified thread as read.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
|
||||||
|
func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications/threads/%v", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetThreadSubscription checks to see if the authenticated user is subscribed
|
||||||
|
// to a thread.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
|
||||||
|
func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string) (*Subscription, *Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sub := new(Subscription)
|
||||||
|
resp, err := s.client.Do(ctx, req, sub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sub, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetThreadSubscription sets the subscription for the specified thread for the
|
||||||
|
// authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
|
||||||
|
func (s *ActivityService) SetThreadSubscription(ctx context.Context, id string, subscription *Subscription) (*Subscription, *Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("PUT", u, subscription)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sub := new(Subscription)
|
||||||
|
resp, err := s.client.Do(ctx, req, sub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sub, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteThreadSubscription deletes the subscription for the specified thread
|
||||||
|
// for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
|
||||||
|
func (s *ActivityService) DeleteThreadSubscription(ctx context.Context, id string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,137 @@
|
||||||
|
// 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"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StarredRepository is returned by ListStarred.
|
||||||
|
type StarredRepository struct {
|
||||||
|
StarredAt *Timestamp `json:"starred_at,omitempty"`
|
||||||
|
Repository *Repository `json:"repo,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stargazer represents a user that has starred a repository.
|
||||||
|
type Stargazer struct {
|
||||||
|
StarredAt *Timestamp `json:"starred_at,omitempty"`
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStargazers lists people who have starred the specified repo.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-stargazers
|
||||||
|
func (s *ActivityService) ListStargazers(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Stargazer, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%s/%s/stargazers", 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", mediaTypeStarringPreview)
|
||||||
|
|
||||||
|
var stargazers []*Stargazer
|
||||||
|
resp, err := s.client.Do(ctx, req, &stargazers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return stargazers, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActivityListStarredOptions specifies the optional parameters to the
|
||||||
|
// ActivityService.ListStarred method.
|
||||||
|
type ActivityListStarredOptions struct {
|
||||||
|
// How to sort the repository list. Possible values are: created, updated,
|
||||||
|
// pushed, full_name. Default is "full_name".
|
||||||
|
Sort string `url:"sort,omitempty"`
|
||||||
|
|
||||||
|
// Direction in which to sort repositories. Possible values are: asc, desc.
|
||||||
|
// Default is "asc" when sort is "full_name", otherwise default is "desc".
|
||||||
|
Direction string `url:"direction,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStarred lists all the repos starred by a user. Passing the empty string
|
||||||
|
// will list the starred repositories for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
|
||||||
|
func (s *ActivityService) ListStarred(ctx context.Context, user string, opt *ActivityListStarredOptions) ([]*StarredRepository, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if user != "" {
|
||||||
|
u = fmt.Sprintf("users/%v/starred", user)
|
||||||
|
} else {
|
||||||
|
u = "user/starred"
|
||||||
|
}
|
||||||
|
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 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)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return repos, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsStarred checks if a repository is starred by authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
|
||||||
|
func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bool, *Response, error) {
|
||||||
|
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
resp, err := s.client.Do(ctx, req, nil)
|
||||||
|
starred, err := parseBoolResponse(err)
|
||||||
|
return starred, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Star a repository as the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/starring/#star-a-repository
|
||||||
|
func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("PUT", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unstar a repository as the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/starring/#unstar-a-repository
|
||||||
|
func (s *ActivityService) Unstar(ctx context.Context, owner, repo string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
// Copyright 2014 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Subscription identifies a repository or thread subscription.
|
||||||
|
type Subscription struct {
|
||||||
|
Subscribed *bool `json:"subscribed,omitempty"`
|
||||||
|
Ignored *bool `json:"ignored,omitempty"`
|
||||||
|
Reason *string `json:"reason,omitempty"`
|
||||||
|
CreatedAt *Timestamp `json:"created_at,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
|
||||||
|
// only populated for repository subscriptions
|
||||||
|
RepositoryURL *string `json:"repository_url,omitempty"`
|
||||||
|
|
||||||
|
// only populated for thread subscriptions
|
||||||
|
ThreadURL *string `json:"thread_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListWatchers lists watchers of a particular repo.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-watchers
|
||||||
|
func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%s/%s/subscribers", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var watchers []*User
|
||||||
|
resp, err := s.client.Do(ctx, req, &watchers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return watchers, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListWatched lists the repositories the specified user is watching. Passing
|
||||||
|
// the empty string will fetch watched repos for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
|
||||||
|
func (s *ActivityService) ListWatched(ctx context.Context, user string, opt *ListOptions) ([]*Repository, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if user != "" {
|
||||||
|
u = fmt.Sprintf("users/%v/subscriptions", user)
|
||||||
|
} else {
|
||||||
|
u = "user/subscriptions"
|
||||||
|
}
|
||||||
|
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 watched []*Repository
|
||||||
|
resp, err := s.client.Do(ctx, req, &watched)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return watched, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepositorySubscription returns the subscription for the specified
|
||||||
|
// repository for the authenticated user. If the authenticated user is not
|
||||||
|
// watching the repository, a nil Subscription is returned.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
|
||||||
|
func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner, repo string) (*Subscription, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sub := new(Subscription)
|
||||||
|
resp, err := s.client.Do(ctx, req, sub)
|
||||||
|
if err != nil {
|
||||||
|
// if it's just a 404, don't return that as an error
|
||||||
|
_, err = parseBoolResponse(err)
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sub, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRepositorySubscription sets the subscription for the specified repository
|
||||||
|
// for the authenticated user.
|
||||||
|
//
|
||||||
|
// To watch a repository, set subscription.Subscribed to true.
|
||||||
|
// To ignore notifications made within a repository, set subscription.Ignored to true.
|
||||||
|
// To stop watching a repository, use DeleteRepositorySubscription.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
|
||||||
|
func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("PUT", u, subscription)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sub := new(Subscription)
|
||||||
|
resp, err := s.client.Do(ctx, req, sub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sub, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRepositorySubscription deletes the subscription for the specified
|
||||||
|
// repository for the authenticated user.
|
||||||
|
//
|
||||||
|
// This is used to stop watching a repository. To control whether or not to
|
||||||
|
// receive notifications from a repository, use SetRepositorySubscription.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
|
||||||
|
func (s *ActivityService) DeleteRepositorySubscription(ctx context.Context, owner, repo string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminService handles communication with the admin related methods of the
|
||||||
|
// GitHub API. These API routes are normally only accessible for GitHub
|
||||||
|
// Enterprise installations.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/enterprise/
|
||||||
|
type AdminService service
|
||||||
|
|
||||||
|
// TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group.
|
||||||
|
type TeamLDAPMapping struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
LDAPDN *string `json:"ldap_dn,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Slug *string `json:"slug,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Privacy *string `json:"privacy,omitempty"`
|
||||||
|
Permission *string `json:"permission,omitempty"`
|
||||||
|
|
||||||
|
MembersURL *string `json:"members_url,omitempty"`
|
||||||
|
RepositoriesURL *string `json:"repositories_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m TeamLDAPMapping) String() string {
|
||||||
|
return Stringify(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserLDAPMapping represents the mapping between a GitHub user and an LDAP user.
|
||||||
|
type UserLDAPMapping struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
LDAPDN *string `json:"ldap_dn,omitempty"`
|
||||||
|
Login *string `json:"login,omitempty"`
|
||||||
|
AvatarURL *string `json:"avatar_url,omitempty"`
|
||||||
|
GravatarID *string `json:"gravatar_id,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
SiteAdmin *bool `json:"site_admin,omitempty"`
|
||||||
|
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
EventsURL *string `json:"events_url,omitempty"`
|
||||||
|
FollowingURL *string `json:"following_url,omitempty"`
|
||||||
|
FollowersURL *string `json:"followers_url,omitempty"`
|
||||||
|
GistsURL *string `json:"gists_url,omitempty"`
|
||||||
|
OrganizationsURL *string `json:"organizations_url,omitempty"`
|
||||||
|
ReceivedEventsURL *string `json:"received_events_url,omitempty"`
|
||||||
|
ReposURL *string `json:"repos_url,omitempty"`
|
||||||
|
StarredURL *string `json:"starred_url,omitempty"`
|
||||||
|
SubscriptionsURL *string `json:"subscriptions_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m UserLDAPMapping) String() string {
|
||||||
|
return Stringify(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user
|
||||||
|
func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) {
|
||||||
|
u := fmt.Sprintf("admin/ldap/users/%v/mapping", user)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, mapping)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(UserLDAPMapping)
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(TeamLDAPMapping)
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,230 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppsService provides access to the installation related functions
|
||||||
|
// in the GitHub API.
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) {
|
||||||
|
u, err := addOptions("app/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 []*Installation
|
||||||
|
resp, err := s.client.Do(ctx, req, &i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListRepos lists the repositories that are accessible to the authenticated installation.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories
|
||||||
|
func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) {
|
||||||
|
u, err := addOptions("installation/repositories", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,435 @@
|
||||||
|
// Copyright 2015 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Scope models a GitHub authorization scope.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth/#scopes
|
||||||
|
type Scope string
|
||||||
|
|
||||||
|
// This is the set of scopes for GitHub API V3
|
||||||
|
const (
|
||||||
|
ScopeNone Scope = "(no scope)" // REVISIT: is this actually returned, or just a documentation artifact?
|
||||||
|
ScopeUser Scope = "user"
|
||||||
|
ScopeUserEmail Scope = "user:email"
|
||||||
|
ScopeUserFollow Scope = "user:follow"
|
||||||
|
ScopePublicRepo Scope = "public_repo"
|
||||||
|
ScopeRepo Scope = "repo"
|
||||||
|
ScopeRepoDeployment Scope = "repo_deployment"
|
||||||
|
ScopeRepoStatus Scope = "repo:status"
|
||||||
|
ScopeDeleteRepo Scope = "delete_repo"
|
||||||
|
ScopeNotifications Scope = "notifications"
|
||||||
|
ScopeGist Scope = "gist"
|
||||||
|
ScopeReadRepoHook Scope = "read:repo_hook"
|
||||||
|
ScopeWriteRepoHook Scope = "write:repo_hook"
|
||||||
|
ScopeAdminRepoHook Scope = "admin:repo_hook"
|
||||||
|
ScopeAdminOrgHook Scope = "admin:org_hook"
|
||||||
|
ScopeReadOrg Scope = "read:org"
|
||||||
|
ScopeWriteOrg Scope = "write:org"
|
||||||
|
ScopeAdminOrg Scope = "admin:org"
|
||||||
|
ScopeReadPublicKey Scope = "read:public_key"
|
||||||
|
ScopeWritePublicKey Scope = "write:public_key"
|
||||||
|
ScopeAdminPublicKey Scope = "admin:public_key"
|
||||||
|
ScopeReadGPGKey Scope = "read:gpg_key"
|
||||||
|
ScopeWriteGPGKey Scope = "write:gpg_key"
|
||||||
|
ScopeAdminGPGKey Scope = "admin:gpg_key"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthorizationsService handles communication with the authorization related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// This service requires HTTP Basic Authentication; it cannot be accessed using
|
||||||
|
// an OAuth token.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/
|
||||||
|
type AuthorizationsService service
|
||||||
|
|
||||||
|
// Authorization represents an individual GitHub authorization.
|
||||||
|
type Authorization struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Scopes []Scope `json:"scopes,omitempty"`
|
||||||
|
Token *string `json:"token,omitempty"`
|
||||||
|
TokenLastEight *string `json:"token_last_eight,omitempty"`
|
||||||
|
HashedToken *string `json:"hashed_token,omitempty"`
|
||||||
|
App *AuthorizationApp `json:"app,omitempty"`
|
||||||
|
Note *string `json:"note,omitempty"`
|
||||||
|
NoteURL *string `json:"note_url,omitempty"`
|
||||||
|
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
|
||||||
|
CreatedAt *Timestamp `json:"created_at,omitempty"`
|
||||||
|
Fingerprint *string `json:"fingerprint,omitempty"`
|
||||||
|
|
||||||
|
// User is only populated by the Check and Reset methods.
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a Authorization) String() string {
|
||||||
|
return Stringify(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthorizationApp represents an individual GitHub app (in the context of authorization).
|
||||||
|
type AuthorizationApp struct {
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
ClientID *string `json:"client_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AuthorizationApp) String() string {
|
||||||
|
return Stringify(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grant represents an OAuth application that has been granted access to an account.
|
||||||
|
type Grant struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
App *AuthorizationApp `json:"app,omitempty"`
|
||||||
|
CreatedAt *Timestamp `json:"created_at,omitempty"`
|
||||||
|
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
|
||||||
|
Scopes []string `json:"scopes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Grant) String() string {
|
||||||
|
return Stringify(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthorizationRequest represents a request to create an authorization.
|
||||||
|
type AuthorizationRequest struct {
|
||||||
|
Scopes []Scope `json:"scopes,omitempty"`
|
||||||
|
Note *string `json:"note,omitempty"`
|
||||||
|
NoteURL *string `json:"note_url,omitempty"`
|
||||||
|
ClientID *string `json:"client_id,omitempty"`
|
||||||
|
ClientSecret *string `json:"client_secret,omitempty"`
|
||||||
|
Fingerprint *string `json:"fingerprint,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AuthorizationRequest) String() string {
|
||||||
|
return Stringify(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthorizationUpdateRequest represents a request to update an authorization.
|
||||||
|
//
|
||||||
|
// Note that for any one update, you must only provide one of the "scopes"
|
||||||
|
// fields. That is, you may provide only one of "Scopes", or "AddScopes", or
|
||||||
|
// "RemoveScopes".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
|
||||||
|
type AuthorizationUpdateRequest struct {
|
||||||
|
Scopes []string `json:"scopes,omitempty"`
|
||||||
|
AddScopes []string `json:"add_scopes,omitempty"`
|
||||||
|
RemoveScopes []string `json:"remove_scopes,omitempty"`
|
||||||
|
Note *string `json:"note,omitempty"`
|
||||||
|
NoteURL *string `json:"note_url,omitempty"`
|
||||||
|
Fingerprint *string `json:"fingerprint,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AuthorizationUpdateRequest) String() string {
|
||||||
|
return Stringify(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List the authorizations for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
|
||||||
|
func (s *AuthorizationsService) List(ctx context.Context, opt *ListOptions) ([]*Authorization, *Response, error) {
|
||||||
|
u := "authorizations"
|
||||||
|
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 auths []*Authorization
|
||||||
|
resp, err := s.client.Do(ctx, req, &auths)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return auths, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*Authorization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("authorizations/%d", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new authorization for the specified OAuth application.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
|
||||||
|
func (s *AuthorizationsService) Create(ctx context.Context, auth *AuthorizationRequest) (*Authorization, *Response, error) {
|
||||||
|
u := "authorizations"
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("POST", u, auth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrCreateForApp creates a new authorization for the specified OAuth
|
||||||
|
// application, only if an authorization for that application doesn’t already
|
||||||
|
// exist for the user.
|
||||||
|
//
|
||||||
|
// If a new token is created, the HTTP status code will be "201 Created", and
|
||||||
|
// the returned Authorization.Token field will be populated. If an existing
|
||||||
|
// token is returned, the status code will be "200 OK" and the
|
||||||
|
// Authorization.Token field will be empty.
|
||||||
|
//
|
||||||
|
// clientID is the OAuth Client ID with which to create the token.
|
||||||
|
//
|
||||||
|
// GitHub API docs:
|
||||||
|
// https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
|
||||||
|
// https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app-and-fingerprint
|
||||||
|
func (s *AuthorizationsService) GetOrCreateForApp(ctx context.Context, clientID string, auth *AuthorizationRequest) (*Authorization, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if auth.Fingerprint == nil || *auth.Fingerprint == "" {
|
||||||
|
u = fmt.Sprintf("authorizations/clients/%v", clientID)
|
||||||
|
} else {
|
||||||
|
u = fmt.Sprintf("authorizations/clients/%v/%v", clientID, *auth.Fingerprint)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("PUT", u, auth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("authorizations/%d", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, auth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("authorizations/%d", id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if an OAuth token is valid for a specific app.
|
||||||
|
//
|
||||||
|
// Note that this operation requires the use of BasicAuth, but where the
|
||||||
|
// username is the OAuth application clientID, and the password is its
|
||||||
|
// clientSecret. Invalid tokens will return a 404 Not Found.
|
||||||
|
//
|
||||||
|
// The returned Authorization.User field will be populated.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#check-an-authorization
|
||||||
|
func (s *AuthorizationsService) Check(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset is used to reset a valid OAuth token without end user involvement.
|
||||||
|
// Applications must save the "token" property in the response, because changes
|
||||||
|
// take effect immediately.
|
||||||
|
//
|
||||||
|
// Note that this operation requires the use of BasicAuth, but where the
|
||||||
|
// username is the OAuth application clientID, and the password is its
|
||||||
|
// clientSecret. Invalid tokens will return a 404 Not Found.
|
||||||
|
//
|
||||||
|
// The returned Authorization.User field will be populated.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization
|
||||||
|
func (s *AuthorizationsService) Reset(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("POST", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke an authorization for an application.
|
||||||
|
//
|
||||||
|
// Note that this operation requires the use of BasicAuth, but where the
|
||||||
|
// username is the OAuth application clientID, and the password is its
|
||||||
|
// clientSecret. Invalid tokens will return a 404 Not Found.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application
|
||||||
|
func (s *AuthorizationsService) Revoke(ctx context.Context, clientID string, token string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListGrants lists the set of OAuth applications that have been granted
|
||||||
|
// access to a user's account. This will return one entry for each application
|
||||||
|
// that has been granted access to the account, regardless of the number of
|
||||||
|
// tokens an application has generated for the user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-grants
|
||||||
|
func (s *AuthorizationsService) ListGrants(ctx context.Context, opt *ListOptions) ([]*Grant, *Response, error) {
|
||||||
|
u, err := addOptions("applications/grants", opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
grants := []*Grant{}
|
||||||
|
resp, err := s.client.Do(ctx, req, &grants)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return grants, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*Grant, *Response, error) {
|
||||||
|
u := fmt.Sprintf("applications/grants/%d", id)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
grant := new(Grant)
|
||||||
|
resp, err := s.client.Do(ctx, req, grant)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return grant, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGrant deletes an OAuth application grant. Deleting an application's
|
||||||
|
// grant will also delete all OAuth tokens associated with the application for
|
||||||
|
// the user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-a-grant
|
||||||
|
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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateImpersonation creates an impersonation OAuth token.
|
||||||
|
//
|
||||||
|
// This requires admin permissions. With the returned Authorization.Token
|
||||||
|
// you can e.g. create or delete a user's public SSH key. NOTE: creating a
|
||||||
|
// new token automatically revokes an existing one.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token
|
||||||
|
func (s *AuthorizationsService) CreateImpersonation(ctx context.Context, username string, authReq *AuthorizationRequest) (*Authorization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("admin/users/%v/authorizations", username)
|
||||||
|
req, err := s.client.NewRequest("POST", u, authReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a := new(Authorization)
|
||||||
|
resp, err := s.client.Do(ctx, req, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return a, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteImpersonation deletes an impersonation OAuth token.
|
||||||
|
//
|
||||||
|
// NOTE: there can be only one at a time.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token
|
||||||
|
func (s *AuthorizationsService) DeleteImpersonation(ctx context.Context, username string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("admin/users/%v/authorizations", username)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,187 @@
|
||||||
|
// 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 provides a client for using the GitHub API.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
import "github.com/google/go-github/github"
|
||||||
|
|
||||||
|
Construct a new GitHub client, then use the various services on the client to
|
||||||
|
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)
|
||||||
|
|
||||||
|
Some API methods have optional parameters that can be passed. For example:
|
||||||
|
|
||||||
|
client := github.NewClient(nil)
|
||||||
|
|
||||||
|
// list public repositories for org "github"
|
||||||
|
opt := &github.RepositoryListByOrgOptions{Type: "public"}
|
||||||
|
repos, _, err := client.Repositories.ListByOrg(ctx, "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 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
|
||||||
|
creating a new client, pass an http.Client that can handle authentication for
|
||||||
|
you. The easiest and recommended way to do this is using the golang.org/x/oauth2
|
||||||
|
library, but you can always use any other library that provides an http.Client.
|
||||||
|
If you have an OAuth2 access token (for example, a personal API token), you can
|
||||||
|
use it with the oauth2 library using:
|
||||||
|
|
||||||
|
import "golang.org/x/oauth2"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx := context.Background()
|
||||||
|
ts := oauth2.StaticTokenSource(
|
||||||
|
&oauth2.Token{AccessToken: "... your access token ..."},
|
||||||
|
)
|
||||||
|
tc := oauth2.NewClient(ctx, ts)
|
||||||
|
|
||||||
|
client := github.NewClient(tc)
|
||||||
|
|
||||||
|
// list all repositories for the authenticated user
|
||||||
|
repos, _, err := client.Repositories.List(ctx, "", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
Note that when using an authenticated Client, all calls made by the client will
|
||||||
|
include the specified OAuth token. Therefore, authenticated clients should
|
||||||
|
almost never be shared between different users.
|
||||||
|
|
||||||
|
See the oauth2 docs for complete instructions on using that library.
|
||||||
|
|
||||||
|
For API methods that require HTTP Basic Authentication, use the
|
||||||
|
BasicAuthTransport.
|
||||||
|
|
||||||
|
GitHub Apps authentication can be provided by the
|
||||||
|
https://github.com/bradleyfalzon/ghinstallation package.
|
||||||
|
|
||||||
|
import "github.com/bradleyfalzon/ghinstallation"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Wrap the shared transport for use with the integration ID 1 authenticating with installation ID 99.
|
||||||
|
itr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, 1, 99, "2016-10-19.private-key.pem")
|
||||||
|
if err != nil {
|
||||||
|
// Handle error.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use installation transport with client
|
||||||
|
client := github.NewClient(&http.Client{Transport: itr})
|
||||||
|
|
||||||
|
// Use client...
|
||||||
|
}
|
||||||
|
|
||||||
|
Rate Limiting
|
||||||
|
|
||||||
|
GitHub imposes a rate limit on all API clients. Unauthenticated clients are
|
||||||
|
limited to 60 requests per hour, while authenticated clients can make up to
|
||||||
|
5,000 requests per hour. The Search API has a custom rate limit. Unauthenticated
|
||||||
|
clients are limited to 10 requests per minute, while authenticated clients
|
||||||
|
can make up to 30 requests per minute. To receive the higher rate limit when
|
||||||
|
making calls that are not issued on behalf of a user,
|
||||||
|
use UnauthenticatedRateLimitedTransport.
|
||||||
|
|
||||||
|
The returned Response.Rate value contains the rate limit information
|
||||||
|
from the most recent API call. If a recent enough response isn't
|
||||||
|
available, you can use RateLimits to fetch the most up-to-date rate
|
||||||
|
limit data for the client.
|
||||||
|
|
||||||
|
To detect an API rate limit error, you can check if its type is *github.RateLimitError:
|
||||||
|
|
||||||
|
repos, _, err := client.Repositories.List(ctx, "", nil)
|
||||||
|
if _, ok := err.(*github.RateLimitError); ok {
|
||||||
|
log.Println("hit rate limit")
|
||||||
|
}
|
||||||
|
|
||||||
|
Learn more about GitHub rate limiting at
|
||||||
|
https://developer.github.com/v3/#rate-limiting.
|
||||||
|
|
||||||
|
Accepted Status
|
||||||
|
|
||||||
|
Some endpoints may return a 202 Accepted status code, meaning that the
|
||||||
|
information required is not yet ready and was scheduled to be gathered on
|
||||||
|
the GitHub side. Methods known to behave like this are documented specifying
|
||||||
|
this behavior.
|
||||||
|
|
||||||
|
To detect this condition of error, you can check if its type is
|
||||||
|
*github.AcceptedError:
|
||||||
|
|
||||||
|
stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
|
||||||
|
if _, ok := err.(*github.AcceptedError); ok {
|
||||||
|
log.Println("scheduled on GitHub side")
|
||||||
|
}
|
||||||
|
|
||||||
|
Conditional Requests
|
||||||
|
|
||||||
|
The GitHub API has good support for conditional requests which will help
|
||||||
|
prevent you from burning through your rate limit, as well as help speed up your
|
||||||
|
application. go-github does not handle conditional requests directly, but is
|
||||||
|
instead designed to work with a caching http.Transport. We recommend using
|
||||||
|
https://github.com/gregjones/httpcache for that.
|
||||||
|
|
||||||
|
Learn more about GitHub conditional requests at
|
||||||
|
https://developer.github.com/v3/#conditional-requests.
|
||||||
|
|
||||||
|
Creating and Updating Resources
|
||||||
|
|
||||||
|
All structs for GitHub resources use pointer values for all non-repeated fields.
|
||||||
|
This allows distinguishing between unset fields and those set to a zero-value.
|
||||||
|
Helper functions have been provided to easily create these pointers for string,
|
||||||
|
bool, and int values. For example:
|
||||||
|
|
||||||
|
// create a new private repository named "foo"
|
||||||
|
repo := &github.Repository{
|
||||||
|
Name: github.String("foo"),
|
||||||
|
Private: github.Bool(true),
|
||||||
|
}
|
||||||
|
client.Repositories.Create(ctx, "", repo)
|
||||||
|
|
||||||
|
Users who have worked with protocol buffers should find this pattern familiar.
|
||||||
|
|
||||||
|
Pagination
|
||||||
|
|
||||||
|
All requests for resource collections (repos, pull requests, issues, etc.)
|
||||||
|
support pagination. Pagination options are described in the
|
||||||
|
github.ListOptions struct and passed to the list methods directly or as an
|
||||||
|
embedded type of a more specific list options struct (for example
|
||||||
|
github.PullRequestListOptions). Pages information is available via the
|
||||||
|
github.Response struct.
|
||||||
|
|
||||||
|
client := github.NewClient(nil)
|
||||||
|
|
||||||
|
opt := &github.RepositoryListByOrgOptions{
|
||||||
|
ListOptions: github.ListOptions{PerPage: 10},
|
||||||
|
}
|
||||||
|
// get all pages of results
|
||||||
|
var allRepos []*github.Repository
|
||||||
|
for {
|
||||||
|
repos, resp, err := client.Repositories.ListByOrg(ctx, "github", opt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
allRepos = append(allRepos, repos...)
|
||||||
|
if resp.NextPage == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
opt.Page = resp.NextPage
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
package github
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,833 @@
|
||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
// These event types are shared between the Events API and used as Webhook payloads.
|
||||||
|
|
||||||
|
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".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#commitcommentevent
|
||||||
|
type CommitCommentEvent struct {
|
||||||
|
Comment *RepositoryComment `json:"comment,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateEvent represents a created repository, branch, or tag.
|
||||||
|
// The Webhook event name is "create".
|
||||||
|
//
|
||||||
|
// Note: webhooks will not receive this event for created repositories.
|
||||||
|
// Additionally, webhooks will not receive this event for tags if more
|
||||||
|
// than three tags are pushed at once.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#createevent
|
||||||
|
type CreateEvent struct {
|
||||||
|
Ref *string `json:"ref,omitempty"`
|
||||||
|
// RefType is the object that was created. Possible values are: "repository", "branch", "tag".
|
||||||
|
RefType *string `json:"ref_type,omitempty"`
|
||||||
|
MasterBranch *string `json:"master_branch,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
PusherType *string `json:"pusher_type,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteEvent represents a deleted branch or tag.
|
||||||
|
// The Webhook event name is "delete".
|
||||||
|
//
|
||||||
|
// Note: webhooks will not receive this event for tags if more than three tags
|
||||||
|
// are deleted at once.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deleteevent
|
||||||
|
type DeleteEvent struct {
|
||||||
|
Ref *string `json:"ref,omitempty"`
|
||||||
|
// RefType is the object that was deleted. Possible values are: "branch", "tag".
|
||||||
|
RefType *string `json:"ref_type,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
PusherType *string `json:"pusher_type,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeploymentEvent represents a deployment.
|
||||||
|
// The Webhook event name is "deployment".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploymentevent
|
||||||
|
type DeploymentEvent struct {
|
||||||
|
Deployment *Deployment `json:"deployment,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeploymentStatusEvent represents a deployment status.
|
||||||
|
// The Webhook event name is "deployment_status".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploymentstatusevent
|
||||||
|
type DeploymentStatusEvent struct {
|
||||||
|
Deployment *Deployment `json:"deployment,omitempty"`
|
||||||
|
DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForkEvent is triggered when a user forks a repository.
|
||||||
|
// The Webhook event name is "fork".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#forkevent
|
||||||
|
type ForkEvent struct {
|
||||||
|
// Forkee is the created repository.
|
||||||
|
Forkee *Repository `json:"forkee,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
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"`
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
Summary *string `json:"summary,omitempty"`
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GollumEvent is triggered when a Wiki page is created or updated.
|
||||||
|
// The Webhook event name is "gollum".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#gollumevent
|
||||||
|
type GollumEvent struct {
|
||||||
|
Pages []*Page `json:"pages,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditChange represents the changes when an issue, pull request, or comment has
|
||||||
|
// been edited.
|
||||||
|
type EditChange struct {
|
||||||
|
Title *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"title,omitempty"`
|
||||||
|
Body *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectChange represents the changes when a project has been edited.
|
||||||
|
type ProjectChange struct {
|
||||||
|
Name *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"name,omitempty"`
|
||||||
|
Body *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectCardChange represents the changes when a project card has been edited.
|
||||||
|
type ProjectCardChange struct {
|
||||||
|
Note *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"note,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectColumnChange represents the changes when a project column has been edited.
|
||||||
|
type ProjectColumnChange struct {
|
||||||
|
Name *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TeamChange represents the changes when a team has been edited.
|
||||||
|
type TeamChange struct {
|
||||||
|
Description *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"description,omitempty"`
|
||||||
|
Name *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"name,omitempty"`
|
||||||
|
Privacy *struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
} `json:"privacy,omitempty"`
|
||||||
|
Repository *struct {
|
||||||
|
Permissions *struct {
|
||||||
|
From *struct {
|
||||||
|
Admin *bool `json:"admin,omitempty"`
|
||||||
|
Pull *bool `json:"pull,omitempty"`
|
||||||
|
Push *bool `json:"push,omitempty"`
|
||||||
|
} `json:"from,omitempty"`
|
||||||
|
} `json:"permissions,omitempty"`
|
||||||
|
} `json:"repository,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallationEvent is triggered when a GitHub App has been installed or uninstalled.
|
||||||
|
// The Webhook event name is "installation".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationevent
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallationRepositoriesEvent is triggered when a repository is added or
|
||||||
|
// removed from an installation. The Webhook event name is "installation_repositories".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent
|
||||||
|
type InstallationRepositoriesEvent struct {
|
||||||
|
// The action that was performed. Can be either "added" or "removed".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
RepositoriesAdded []*Repository `json:"repositories_added,omitempty"`
|
||||||
|
RepositoriesRemoved []*Repository `json:"repositories_removed,omitempty"`
|
||||||
|
RepositorySelection *string `json:"repository_selection,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueCommentEvent is triggered when an issue comment is created on an issue
|
||||||
|
// or pull request.
|
||||||
|
// The Webhook event name is "issue_comment".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#issuecommentevent
|
||||||
|
type IssueCommentEvent struct {
|
||||||
|
// Action is the action that was performed on the comment.
|
||||||
|
// Possible values are: "created", "edited", "deleted".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Issue *Issue `json:"issue,omitempty"`
|
||||||
|
Comment *IssueComment `json:"comment,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuesEvent is triggered when an issue is assigned, unassigned, labeled,
|
||||||
|
// unlabeled, opened, closed, or reopened.
|
||||||
|
// The Webhook event name is "issues".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#issuesevent
|
||||||
|
type IssuesEvent struct {
|
||||||
|
// Action is the action that was performed. Possible values are: "assigned",
|
||||||
|
// "unassigned", "labeled", "unlabeled", "opened", "closed", "reopened", "edited".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Issue *Issue `json:"issue,omitempty"`
|
||||||
|
Assignee *User `json:"assignee,omitempty"`
|
||||||
|
Label *Label `json:"label,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LabelEvent is triggered when a repository's label is created, edited, or deleted.
|
||||||
|
// The Webhook event name is "label"
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#labelevent
|
||||||
|
type LabelEvent struct {
|
||||||
|
// Action is the action that was performed. Possible values are:
|
||||||
|
// "created", "edited", "deleted"
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Label *Label `json:"label,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Changes *EditChange `json:"changes,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
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".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#memberevent
|
||||||
|
type MemberEvent struct {
|
||||||
|
// Action is the action that was performed. Possible value is: "added".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Member *User `json:"member,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MembershipEvent is triggered when a user is added or removed from a team.
|
||||||
|
// The Webhook event name is "membership".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to
|
||||||
|
// trigger organization webhooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#membershipevent
|
||||||
|
type MembershipEvent struct {
|
||||||
|
// Action is the action that was performed. Possible values are: "added", "removed".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
// Scope is the scope of the membership. Possible value is: "team".
|
||||||
|
Scope *string `json:"scope,omitempty"`
|
||||||
|
Member *User `json:"member,omitempty"`
|
||||||
|
Team *Team `json:"team,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MilestoneEvent is triggered when a milestone is created, closed, opened, edited, or deleted.
|
||||||
|
// The Webhook event name is "milestone".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#milestoneevent
|
||||||
|
type MilestoneEvent struct {
|
||||||
|
// Action is the action that was performed. Possible values are:
|
||||||
|
// "created", "closed", "opened", "edited", "deleted"
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Milestone *Milestone `json:"milestone,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"`
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrganizationEvent is triggered when a user is added, removed, or invited to an organization.
|
||||||
|
// Events of this type are not visible in timelines. These events are only used to trigger organization hooks.
|
||||||
|
// Webhook event name is "organization".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#organizationevent
|
||||||
|
type OrganizationEvent struct {
|
||||||
|
// Action is the action that was performed.
|
||||||
|
// Can be one of "member_added", "member_removed", or "member_invited".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
|
||||||
|
// Invitaion is the invitation for the user or email if the action is "member_invited".
|
||||||
|
Invitation *Invitation `json:"invitation,omitempty"`
|
||||||
|
|
||||||
|
// Membership is the membership between the user and the organization.
|
||||||
|
// Not present when the action is "member_invited".
|
||||||
|
Membership *Membership `json:"membership,omitempty"`
|
||||||
|
|
||||||
|
Organization *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrgBlockEvent is triggered when an organization blocks or unblocks a user.
|
||||||
|
// The Webhook event name is "org_block".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#orgblockevent
|
||||||
|
type OrgBlockEvent struct {
|
||||||
|
// Action is the action that was performed.
|
||||||
|
// Can be "blocked" or "unblocked".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
BlockedUser *User `json:"blocked_user,omitempty"`
|
||||||
|
Organization *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PageBuildEvent represents an attempted build of a GitHub Pages site, whether
|
||||||
|
// successful or not.
|
||||||
|
// The Webhook event name is "page_build".
|
||||||
|
//
|
||||||
|
// This event is triggered on push to a GitHub Pages enabled branch (gh-pages
|
||||||
|
// for project pages, master for user and organization pages).
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pagebuildevent
|
||||||
|
type PageBuildEvent struct {
|
||||||
|
Build *PagesBuild `json:"build,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PingEvent is triggered when a Webhook is added to GitHub.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/webhooks/#ping-event
|
||||||
|
type PingEvent struct {
|
||||||
|
// Random string of GitHub zen.
|
||||||
|
Zen *string `json:"zen,omitempty"`
|
||||||
|
// The ID of the webhook that triggered the ping.
|
||||||
|
HookID *int64 `json:"hook_id,omitempty"`
|
||||||
|
// The webhook configuration.
|
||||||
|
Hook *Hook `json:"hook,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectEvent is triggered when project is created, modified or deleted.
|
||||||
|
// The webhook event name is "project".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectevent
|
||||||
|
type ProjectEvent struct {
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Changes *ProjectChange `json:"changes,omitempty"`
|
||||||
|
Project *Project `json:"project,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectCardEvent is triggered when a project card is created, updated, moved, converted to an issue, or deleted.
|
||||||
|
// The webhook event name is "project_card".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectcardevent
|
||||||
|
type ProjectCardEvent struct {
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Changes *ProjectCardChange `json:"changes,omitempty"`
|
||||||
|
AfterID *int64 `json:"after_id,omitempty"`
|
||||||
|
ProjectCard *ProjectCard `json:"project_card,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectColumnEvent is triggered when a project column is created, updated, moved, or deleted.
|
||||||
|
// The webhook event name is "project_column".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectcolumnevent
|
||||||
|
type ProjectColumnEvent struct {
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Changes *ProjectColumnChange `json:"changes,omitempty"`
|
||||||
|
AfterID *int64 `json:"after_id,omitempty"`
|
||||||
|
ProjectColumn *ProjectColumn `json:"project_column,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicEvent is triggered when a private repository is open sourced.
|
||||||
|
// According to GitHub: "Without a doubt: the best GitHub event."
|
||||||
|
// The Webhook event name is "public".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#publicevent
|
||||||
|
type PublicEvent struct {
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestEvent is triggered when a pull request is assigned, unassigned,
|
||||||
|
// labeled, unlabeled, opened, closed, reopened, or synchronized.
|
||||||
|
// The Webhook event name is "pull_request".
|
||||||
|
//
|
||||||
|
// 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", "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"`
|
||||||
|
// 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
|
||||||
|
// request.
|
||||||
|
// The Webhook event name is "pull_request_review".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
|
||||||
|
type PullRequestReviewEvent struct {
|
||||||
|
// Action is always "submitted".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Review *PullRequestReview `json:"review,omitempty"`
|
||||||
|
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
|
||||||
|
// The following field is only present when the webhook is triggered on
|
||||||
|
// a repository belonging to an organization.
|
||||||
|
Organization *Organization `json:"organization,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestReviewCommentEvent is triggered when a comment is created on a
|
||||||
|
// portion of the unified diff of a pull request.
|
||||||
|
// The Webhook event name is "pull_request_review_comment".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent
|
||||||
|
type PullRequestReviewCommentEvent struct {
|
||||||
|
// Action is the action that was performed on the comment.
|
||||||
|
// Possible values are: "created", "edited", "deleted".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
||||||
|
Comment *PullRequestComment `json:"comment,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushEvent represents a git push to a GitHub repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pushevent
|
||||||
|
type PushEvent struct {
|
||||||
|
PushID *int64 `json:"push_id,omitempty"`
|
||||||
|
Head *string `json:"head,omitempty"`
|
||||||
|
Ref *string `json:"ref,omitempty"`
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
Commits []PushEventCommit `json:"commits,omitempty"`
|
||||||
|
Before *string `json:"before,omitempty"`
|
||||||
|
DistinctSize *int `json:"distinct_size,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
After *string `json:"after,omitempty"`
|
||||||
|
Created *bool `json:"created,omitempty"`
|
||||||
|
Deleted *bool `json:"deleted,omitempty"`
|
||||||
|
Forced *bool `json:"forced,omitempty"`
|
||||||
|
BaseRef *string `json:"base_ref,omitempty"`
|
||||||
|
Compare *string `json:"compare,omitempty"`
|
||||||
|
Repo *PushEventRepository `json:"repository,omitempty"`
|
||||||
|
HeadCommit *PushEventCommit `json:"head_commit,omitempty"`
|
||||||
|
Pusher *User `json:"pusher,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p PushEvent) String() string {
|
||||||
|
return Stringify(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushEventCommit represents a git commit in a GitHub PushEvent.
|
||||||
|
type PushEventCommit struct {
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
Author *CommitAuthor `json:"author,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Distinct *bool `json:"distinct,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Events API.
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
ID *string `json:"id,omitempty"`
|
||||||
|
TreeID *string `json:"tree_id,omitempty"`
|
||||||
|
Timestamp *Timestamp `json:"timestamp,omitempty"`
|
||||||
|
Committer *CommitAuthor `json:"committer,omitempty"`
|
||||||
|
Added []string `json:"added,omitempty"`
|
||||||
|
Removed []string `json:"removed,omitempty"`
|
||||||
|
Modified []string `json:"modified,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p PushEventCommit) String() string {
|
||||||
|
return Stringify(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushEventRepository represents the repo object in a PushEvent payload.
|
||||||
|
type PushEventRepository struct {
|
||||||
|
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.
|
||||||
|
type PushEventRepoOwner struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Email *string `json:"email,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReleaseEvent is triggered when a release is published.
|
||||||
|
// The Webhook event name is "release".
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#releaseevent
|
||||||
|
type ReleaseEvent struct {
|
||||||
|
// Action is the action that was performed. Possible value is: "published".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Release *RepositoryRelease `json:"release,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepositoryEvent is triggered when a repository is created.
|
||||||
|
// The Webhook event name is "repository".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to
|
||||||
|
// trigger organization webhooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryevent
|
||||||
|
type RepositoryEvent struct {
|
||||||
|
// Action is the action that was performed. Possible values are: "created", "deleted",
|
||||||
|
// "publicized", "privatized".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
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".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines, they are only used to
|
||||||
|
// trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#statusevent
|
||||||
|
type StatusEvent struct {
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
// State is the new state. Possible values are: "pending", "success", "failure", "error".
|
||||||
|
State *string `json:"state,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
TargetURL *string `json:"target_url,omitempty"`
|
||||||
|
Branches []*Branch `json:"branches,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Context *string `json:"context,omitempty"`
|
||||||
|
Commit *RepositoryCommit `json:"commit,omitempty"`
|
||||||
|
CreatedAt *Timestamp `json:"created_at,omitempty"`
|
||||||
|
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TeamEvent is triggered when an organization's team is created, modified or deleted.
|
||||||
|
// The Webhook event name is "team".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines. These events are only used
|
||||||
|
// to trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#teamevent
|
||||||
|
type TeamEvent struct {
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
Team *Team `json:"team,omitempty"`
|
||||||
|
Changes *TeamChange `json:"changes,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TeamAddEvent is triggered when a repository is added to a team.
|
||||||
|
// The Webhook event name is "team_add".
|
||||||
|
//
|
||||||
|
// Events of this type are not visible in timelines. These events are only used
|
||||||
|
// to trigger hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#teamaddevent
|
||||||
|
type TeamAddEvent struct {
|
||||||
|
Team *Team `json:"team,omitempty"`
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Org *Organization `json:"organization,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WatchEvent is related to starring a repository, not watching. See this API
|
||||||
|
// blog post for an explanation: https://developer.github.com/changes/2012-09-05-watcher-api/
|
||||||
|
//
|
||||||
|
// The event’s actor is the user who starred a repository, and the event’s
|
||||||
|
// repository is the repository that was starred.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#watchevent
|
||||||
|
type WatchEvent struct {
|
||||||
|
// Action is the action that was performed. Possible value is: "started".
|
||||||
|
Action *string `json:"action,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Repo *Repository `json:"repository,omitempty"`
|
||||||
|
Sender *User `json:"sender,omitempty"`
|
||||||
|
Installation *Installation `json:"installation,omitempty"`
|
||||||
|
}
|
|
@ -0,0 +1,332 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
// gen-accessors generates accessor methods for structs with pointer fields.
|
||||||
|
//
|
||||||
|
// It is meant to be used by the go-github authors in conjunction with the
|
||||||
|
// go generate tool before sending a commit to GitHub.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"go/ast"
|
||||||
|
"go/format"
|
||||||
|
"go/parser"
|
||||||
|
"go/token"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
fileSuffix = "-accessors.go"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
verbose = flag.Bool("v", false, "Print verbose log messages")
|
||||||
|
|
||||||
|
sourceTmpl = template.Must(template.New("source").Parse(source))
|
||||||
|
|
||||||
|
// blacklistStructMethod lists "struct.method" combos to skip.
|
||||||
|
blacklistStructMethod = map[string]bool{
|
||||||
|
"RepositoryContent.GetContent": true,
|
||||||
|
"Client.GetBaseURL": true,
|
||||||
|
"Client.GetUploadURL": true,
|
||||||
|
"ErrorResponse.GetResponse": true,
|
||||||
|
"RateLimitError.GetResponse": true,
|
||||||
|
"AbuseRateLimitError.GetResponse": true,
|
||||||
|
}
|
||||||
|
// blacklistStruct lists structs to skip.
|
||||||
|
blacklistStruct = map[string]bool{
|
||||||
|
"Client": true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func logf(fmt string, args ...interface{}) {
|
||||||
|
if *verbose {
|
||||||
|
log.Printf(fmt, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
fset := token.NewFileSet()
|
||||||
|
|
||||||
|
pkgs, err := parser.ParseDir(fset, ".", sourceFilter, 0)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for pkgName, pkg := range pkgs {
|
||||||
|
t := &templateData{
|
||||||
|
filename: pkgName + fileSuffix,
|
||||||
|
Year: 2017,
|
||||||
|
Package: pkgName,
|
||||||
|
Imports: map[string]string{},
|
||||||
|
}
|
||||||
|
for filename, f := range pkg.Files {
|
||||||
|
logf("Processing %v...", filename)
|
||||||
|
if err := t.processAST(f); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := t.dump(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logf("Done.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *templateData) processAST(f *ast.File) error {
|
||||||
|
for _, decl := range f.Decls {
|
||||||
|
gd, ok := decl.(*ast.GenDecl)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, spec := range gd.Specs {
|
||||||
|
ts, ok := spec.(*ast.TypeSpec)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
for _, field := range st.Fields.List {
|
||||||
|
se, ok := field.Type.(*ast.StarExpr)
|
||||||
|
if len(field.Names) == 0 || !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldName := field.Names[0]
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
switch x := se.X.(type) {
|
||||||
|
case *ast.ArrayType:
|
||||||
|
t.addArrayType(x, ts.Name.String(), fieldName.String())
|
||||||
|
case *ast.Ident:
|
||||||
|
t.addIdent(x, ts.Name.String(), fieldName.String())
|
||||||
|
case *ast.MapType:
|
||||||
|
t.addMapType(x, ts.Name.String(), fieldName.String())
|
||||||
|
case *ast.SelectorExpr:
|
||||||
|
t.addSelectorExpr(x, ts.Name.String(), fieldName.String())
|
||||||
|
default:
|
||||||
|
logf("processAST: type %q, field %q, unknown %T: %+v", ts.Name, fieldName, x, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sourceFilter(fi os.FileInfo) bool {
|
||||||
|
return !strings.HasSuffix(fi.Name(), "_test.go") && !strings.HasSuffix(fi.Name(), fileSuffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *templateData) dump() error {
|
||||||
|
if len(t.Getters) == 0 {
|
||||||
|
logf("No getters for %v; skipping.", t.filename)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort getters by ReceiverType.FieldName.
|
||||||
|
sort.Sort(byName(t.Getters))
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := sourceTmpl.Execute(&buf, t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
clean, err := format.Source(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logf("Writing %v...", t.filename)
|
||||||
|
return ioutil.WriteFile(t.filename, clean, 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newGetter(receiverType, fieldName, fieldType, zeroValue string, namedStruct bool) *getter {
|
||||||
|
return &getter{
|
||||||
|
sortVal: strings.ToLower(receiverType) + "." + strings.ToLower(fieldName),
|
||||||
|
ReceiverVar: strings.ToLower(receiverType[:1]),
|
||||||
|
ReceiverType: receiverType,
|
||||||
|
FieldName: fieldName,
|
||||||
|
FieldType: fieldType,
|
||||||
|
ZeroValue: zeroValue,
|
||||||
|
NamedStruct: namedStruct,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *templateData) addArrayType(x *ast.ArrayType, receiverType, fieldName string) {
|
||||||
|
var eltType string
|
||||||
|
switch elt := x.Elt.(type) {
|
||||||
|
case *ast.Ident:
|
||||||
|
eltType = elt.String()
|
||||||
|
default:
|
||||||
|
logf("addArrayType: type %q, field %q: unknown elt type: %T %+v; skipping.", receiverType, fieldName, elt, elt)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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", "int64":
|
||||||
|
zeroValue = "0"
|
||||||
|
case "string":
|
||||||
|
zeroValue = `""`
|
||||||
|
case "bool":
|
||||||
|
zeroValue = "false"
|
||||||
|
case "Timestamp":
|
||||||
|
zeroValue = "Timestamp{}"
|
||||||
|
default:
|
||||||
|
zeroValue = "nil"
|
||||||
|
namedStruct = true
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Getters = append(t.Getters, newGetter(receiverType, fieldName, x.String(), zeroValue, namedStruct))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *templateData) addMapType(x *ast.MapType, receiverType, fieldName string) {
|
||||||
|
var keyType string
|
||||||
|
switch key := x.Key.(type) {
|
||||||
|
case *ast.Ident:
|
||||||
|
keyType = key.String()
|
||||||
|
default:
|
||||||
|
logf("addMapType: type %q, field %q: unknown key type: %T %+v; skipping.", receiverType, fieldName, key, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var valueType string
|
||||||
|
switch value := x.Value.(type) {
|
||||||
|
case *ast.Ident:
|
||||||
|
valueType = value.String()
|
||||||
|
default:
|
||||||
|
logf("addMapType: type %q, field %q: unknown value type: %T %+v; skipping.", receiverType, fieldName, value, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) {
|
||||||
|
if strings.ToLower(fieldName[:1]) == fieldName[:1] { // Non-exported field.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var xX string
|
||||||
|
if xx, ok := x.X.(*ast.Ident); ok {
|
||||||
|
xX = xx.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
switch xX {
|
||||||
|
case "time", "json":
|
||||||
|
if xX == "json" {
|
||||||
|
t.Imports["encoding/json"] = "encoding/json"
|
||||||
|
} else {
|
||||||
|
t.Imports[xX] = xX
|
||||||
|
}
|
||||||
|
fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name)
|
||||||
|
zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name)
|
||||||
|
if xX == "time" && x.Sel.Name == "Duration" {
|
||||||
|
zeroValue = "0"
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type templateData struct {
|
||||||
|
filename string
|
||||||
|
Year int
|
||||||
|
Package string
|
||||||
|
Imports map[string]string
|
||||||
|
Getters []*getter
|
||||||
|
}
|
||||||
|
|
||||||
|
type getter struct {
|
||||||
|
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
|
||||||
|
|
||||||
|
func (b byName) Len() int { return len(b) }
|
||||||
|
func (b byName) Less(i, j int) bool { return b[i].sortVal < b[j].sortVal }
|
||||||
|
func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
|
||||||
|
const source = `// Copyright {{.Year}} 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.
|
||||||
|
|
||||||
|
// Code generated by gen-accessors; DO NOT EDIT.
|
||||||
|
|
||||||
|
package {{.Package}}
|
||||||
|
{{with .Imports}}
|
||||||
|
import (
|
||||||
|
{{- range . -}}
|
||||||
|
"{{.}}"
|
||||||
|
{{end -}}
|
||||||
|
)
|
||||||
|
{{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 {
|
||||||
|
return {{.ZeroValue}}
|
||||||
|
}
|
||||||
|
return *{{.ReceiverVar}}.{{.FieldName}}
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
`
|
|
@ -0,0 +1,358 @@
|
||||||
|
// Copyright 2013 The go-github AUTHORS. All rights reserved.
|
||||||
|
//
|
||||||
|
// Use of this source code is governed by BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package github
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GistsService handles communication with the Gist related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/
|
||||||
|
type GistsService service
|
||||||
|
|
||||||
|
// Gist represents a GitHub's gist.
|
||||||
|
type Gist struct {
|
||||||
|
ID *string `json:"id,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Public *bool `json:"public,omitempty"`
|
||||||
|
Owner *User `json:"owner,omitempty"`
|
||||||
|
Files map[GistFilename]GistFile `json:"files,omitempty"`
|
||||||
|
Comments *int `json:"comments,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
GitPullURL *string `json:"git_pull_url,omitempty"`
|
||||||
|
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 {
|
||||||
|
return Stringify(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GistFilename represents filename on a gist.
|
||||||
|
type GistFilename string
|
||||||
|
|
||||||
|
// GistFile represents a file on a gist.
|
||||||
|
type GistFile struct {
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
Filename *string `json:"filename,omitempty"`
|
||||||
|
Language *string `json:"language,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
RawURL *string `json:"raw_url,omitempty"`
|
||||||
|
Content *string `json:"content,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g GistFile) String() string {
|
||||||
|
return Stringify(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GistCommit represents a commit on a gist.
|
||||||
|
type GistCommit struct {
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Version *string `json:"version,omitempty"`
|
||||||
|
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 {
|
||||||
|
return Stringify(gc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GistFork represents a fork of a gist.
|
||||||
|
type GistFork struct {
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
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 {
|
||||||
|
return Stringify(gf)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GistListOptions specifies the optional parameters to the
|
||||||
|
// GistsService.List, GistsService.ListAll, and GistsService.ListStarred methods.
|
||||||
|
type GistListOptions struct {
|
||||||
|
// Since filters Gists by time.
|
||||||
|
Since time.Time `url:"since,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// List gists for a user. Passing the empty string will list
|
||||||
|
// all public gists if called anonymously. However, if the call
|
||||||
|
// is authenticated, it will returns all gists for the authenticated
|
||||||
|
// user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
|
||||||
|
func (s *GistsService) List(ctx context.Context, user string, opt *GistListOptions) ([]*Gist, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if user != "" {
|
||||||
|
u = fmt.Sprintf("users/%v/gists", user)
|
||||||
|
} else {
|
||||||
|
u = "gists"
|
||||||
|
}
|
||||||
|
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 gists []*Gist
|
||||||
|
resp, err := s.client.Do(ctx, req, &gists)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gists, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAll lists all public gists.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
|
||||||
|
func (s *GistsService) ListAll(ctx context.Context, opt *GistListOptions) ([]*Gist, *Response, error) {
|
||||||
|
u, err := addOptions("gists/public", opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var gists []*Gist
|
||||||
|
resp, err := s.client.Do(ctx, req, &gists)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gists, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStarred lists starred gists of authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
|
||||||
|
func (s *GistsService) ListStarred(ctx context.Context, opt *GistListOptions) ([]*Gist, *Response, error) {
|
||||||
|
u, err := addOptions("gists/starred", opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var gists []*Gist
|
||||||
|
resp, err := s.client.Do(ctx, req, &gists)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gists, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-single-gist
|
||||||
|
func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v", id)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
gist := new(Gist)
|
||||||
|
resp, err := s.client.Do(ctx, req, gist)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gist, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRevision gets a specific revision of a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
|
||||||
|
func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/%v", id, sha)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
gist := new(Gist)
|
||||||
|
resp, err := s.client.Do(ctx, req, gist)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gist, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a gist for authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#create-a-gist
|
||||||
|
func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response, error) {
|
||||||
|
u := "gists"
|
||||||
|
req, err := s.client.NewRequest("POST", u, gist)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
g := new(Gist)
|
||||||
|
resp, err := s.client.Do(ctx, req, g)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return g, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#edit-a-gist
|
||||||
|
func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v", id)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, gist)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
g := new(Gist)
|
||||||
|
resp, err := s.client.Do(ctx, req, g)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return g, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCommits lists commits of a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#list-gist-commits
|
||||||
|
func (s *GistsService) ListCommits(ctx context.Context, id string, opt *ListOptions) ([]*GistCommit, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/commits", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var gistCommits []*GistCommit
|
||||||
|
resp, err := s.client.Do(ctx, req, &gistCommits)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gistCommits, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#delete-a-gist
|
||||||
|
func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v", id)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Star a gist on behalf of authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#star-a-gist
|
||||||
|
func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/star", id)
|
||||||
|
req, err := s.client.NewRequest("PUT", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unstar a gist on a behalf of authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#unstar-a-gist
|
||||||
|
func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/star", id)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsStarred checks if a gist is starred by authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#check-if-a-gist-is-starred
|
||||||
|
func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/star", id)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
resp, err := s.client.Do(ctx, req, nil)
|
||||||
|
starred, err := parseBoolResponse(err)
|
||||||
|
return starred, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fork a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#fork-a-gist
|
||||||
|
func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/forks", id)
|
||||||
|
req, err := s.client.NewRequest("POST", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
g := new(Gist)
|
||||||
|
resp, err := s.client.Do(ctx, req, g)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return g, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListForks lists forks of a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/#list-gist-forks
|
||||||
|
func (s *GistsService) ListForks(ctx context.Context, id string) ([]*GistFork, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/forks", id)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var gistForks []*GistFork
|
||||||
|
resp, err := s.client.Do(ctx, req, &gistForks)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gistForks, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GistComment represents a Gist comment.
|
||||||
|
type GistComment struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Body *string `json:"body,omitempty"`
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g GistComment) String() string {
|
||||||
|
return Stringify(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListComments lists all comments for a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
|
||||||
|
func (s *GistsService) ListComments(ctx context.Context, gistID string, opt *ListOptions) ([]*GistComment, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/comments", gistID)
|
||||||
|
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 comments []*GistComment
|
||||||
|
resp, err := s.client.Do(ctx, req, &comments)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return comments, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*GistComment, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(GistComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateComment creates a comment for a gist.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gists/comments/#create-a-comment
|
||||||
|
func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/comments", gistID)
|
||||||
|
req, err := s.client.NewRequest("POST", u, comment)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(GistComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(GistComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// GitService handles communication with the git data related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/
|
||||||
|
type GitService service
|
|
@ -0,0 +1,69 @@
|
||||||
|
// 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 (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Blob represents a blob object.
|
||||||
|
type Blob struct {
|
||||||
|
Content *string `json:"content,omitempty"`
|
||||||
|
Encoding *string `json:"encoding,omitempty"`
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
NodeID *string `json:"node_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
blob := new(Blob)
|
||||||
|
resp, err := s.client.Do(ctx, req, blob)
|
||||||
|
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
|
||||||
|
func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string, blob *Blob) (*Blob, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/blobs", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("POST", u, blob)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
t := new(Blob)
|
||||||
|
resp, err := s.client.Do(ctx, req, t)
|
||||||
|
return t, resp, err
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SignatureVerification represents GPG signature verification.
|
||||||
|
type SignatureVerification struct {
|
||||||
|
Verified *bool `json:"verified,omitempty"`
|
||||||
|
Reason *string `json:"reason,omitempty"`
|
||||||
|
Signature *string `json:"signature,omitempty"`
|
||||||
|
Payload *string `json:"payload,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit represents a GitHub commit.
|
||||||
|
type Commit struct {
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
Author *CommitAuthor `json:"author,omitempty"`
|
||||||
|
Committer *CommitAuthor `json:"committer,omitempty"`
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
Tree *Tree `json:"tree,omitempty"`
|
||||||
|
Parents []Commit `json:"parents,omitempty"`
|
||||||
|
Stats *CommitStats `json:"stats,omitempty"`
|
||||||
|
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
|
||||||
|
// Pulls.ListCommits, Repositories.ListCommits, etc.
|
||||||
|
CommentCount *int `json:"comment_count,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Commit) String() string {
|
||||||
|
return Stringify(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommitAuthor represents the author or committer of a commit. The commit
|
||||||
|
// author may not correspond to a GitHub User.
|
||||||
|
type CommitAuthor struct {
|
||||||
|
Date *time.Time `json:"date,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Email *string `json:"email,omitempty"`
|
||||||
|
|
||||||
|
// The following fields are only populated by Webhook events.
|
||||||
|
Login *string `json:"username,omitempty"` // Renamed for go-github consistency.
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommitAuthor) String() string {
|
||||||
|
return Stringify(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(Commit)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createCommit represents the body of a CreateCommit request.
|
||||||
|
type createCommit struct {
|
||||||
|
Author *CommitAuthor `json:"author,omitempty"`
|
||||||
|
Committer *CommitAuthor `json:"committer,omitempty"`
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
Tree *string `json:"tree,omitempty"`
|
||||||
|
Parents []string `json:"parents,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateCommit creates a new commit in a repository.
|
||||||
|
// commit must not be nil.
|
||||||
|
//
|
||||||
|
// The commit.Committer is optional and will be filled with the commit.Author
|
||||||
|
// data if omitted. If the commit.Author is omitted, it will be filled in with
|
||||||
|
// the authenticated user’s information and the current date.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/commits/#create-a-commit
|
||||||
|
func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string, commit *Commit) (*Commit, *Response, error) {
|
||||||
|
if commit == nil {
|
||||||
|
return nil, nil, fmt.Errorf("commit must be provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/commits", owner, repo)
|
||||||
|
|
||||||
|
parents := make([]string, len(commit.Parents))
|
||||||
|
for i, parent := range commit.Parents {
|
||||||
|
parents[i] = *parent.SHA
|
||||||
|
}
|
||||||
|
|
||||||
|
body := &createCommit{
|
||||||
|
Author: commit.Author,
|
||||||
|
Committer: commit.Committer,
|
||||||
|
Message: commit.Message,
|
||||||
|
Parents: parents,
|
||||||
|
}
|
||||||
|
if commit.Tree != nil {
|
||||||
|
body.Tree = commit.Tree.SHA
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("POST", u, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(Commit)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,218 @@
|
||||||
|
// 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"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference represents a GitHub reference.
|
||||||
|
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 {
|
||||||
|
return Stringify(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitObject represents a Git object.
|
||||||
|
type GitObject struct {
|
||||||
|
Type *string `json:"type"`
|
||||||
|
SHA *string `json:"sha"`
|
||||||
|
URL *string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o GitObject) String() string {
|
||||||
|
return Stringify(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createRefRequest represents the payload for creating a reference.
|
||||||
|
type createRefRequest struct {
|
||||||
|
Ref *string `json:"ref"`
|
||||||
|
SHA *string `json:"sha"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateRefRequest represents the payload for updating a reference.
|
||||||
|
type updateRefRequest struct {
|
||||||
|
SHA *string `json:"sha"`
|
||||||
|
Force *bool `json:"force"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRef fetches a single Reference object for a given Git ref.
|
||||||
|
// If there is no exact match, GetRef will return an error.
|
||||||
|
//
|
||||||
|
// Note: The GitHub API can return multiple matches.
|
||||||
|
// If you wish to use this functionality please use the GetRefs() method.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
|
||||||
|
func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) {
|
||||||
|
ref = strings.TrimPrefix(ref, "refs/")
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := new(Reference)
|
||||||
|
resp, err := s.client.Do(ctx, req, r)
|
||||||
|
if _, ok := err.(*json.UnmarshalTypeError); ok {
|
||||||
|
// Multiple refs, means there wasn't an exact match.
|
||||||
|
return nil, resp, errors.New("no exact match found for this ref")
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRefs fetches a slice of Reference objects for a given Git ref.
|
||||||
|
// If there is an exact match, only that ref is returned.
|
||||||
|
// If there is no exact match, GitHub returns all refs that start with ref.
|
||||||
|
// If returned error is nil, there will be at least 1 ref returned.
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// "heads/featureA" -> ["refs/heads/featureA"] // Exact match, single ref is returned.
|
||||||
|
// "heads/feature" -> ["refs/heads/featureA", "refs/heads/featureB"] // All refs that start with ref.
|
||||||
|
// "heads/notexist" -> [] // Returns an error.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
|
||||||
|
func (s *GitService) GetRefs(ctx context.Context, owner string, repo string, ref string) ([]*Reference, *Response, error) {
|
||||||
|
ref = strings.TrimPrefix(ref, "refs/")
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var rawJSON json.RawMessage
|
||||||
|
resp, err := s.client.Do(ctx, req, &rawJSON)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prioritize the most common case: a single returned ref.
|
||||||
|
r := new(Reference)
|
||||||
|
singleUnmarshalError := json.Unmarshal(rawJSON, r)
|
||||||
|
if singleUnmarshalError == nil {
|
||||||
|
return []*Reference{r}, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to unmarshal multiple refs.
|
||||||
|
var rs []*Reference
|
||||||
|
multipleUnmarshalError := json.Unmarshal(rawJSON, &rs)
|
||||||
|
if multipleUnmarshalError == nil {
|
||||||
|
if len(rs) == 0 {
|
||||||
|
return nil, resp, fmt.Errorf("unexpected response from GitHub API: an array of refs with length 0")
|
||||||
|
}
|
||||||
|
return rs, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, resp, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", singleUnmarshalError, multipleUnmarshalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReferenceListOptions specifies optional parameters to the
|
||||||
|
// GitService.ListRefs method.
|
||||||
|
type ReferenceListOptions struct {
|
||||||
|
Type string `url:"-"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRefs lists all refs in a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-all-references
|
||||||
|
func (s *GitService) ListRefs(ctx context.Context, owner, repo string, opt *ReferenceListOptions) ([]*Reference, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if opt != nil && opt.Type != "" {
|
||||||
|
u = fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, opt.Type)
|
||||||
|
} else {
|
||||||
|
u = fmt.Sprintf("repos/%v/%v/git/refs", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var rs []*Reference
|
||||||
|
resp, err := s.client.Do(ctx, req, &rs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRef creates a new ref in a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#create-a-reference
|
||||||
|
func (s *GitService) CreateRef(ctx context.Context, owner string, repo string, ref *Reference) (*Reference, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("POST", u, &createRefRequest{
|
||||||
|
// back-compat with previous behavior that didn't require 'refs/' prefix
|
||||||
|
Ref: String("refs/" + strings.TrimPrefix(*ref.Ref, "refs/")),
|
||||||
|
SHA: ref.Object.SHA,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := new(Reference)
|
||||||
|
resp, err := s.client.Do(ctx, req, r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateRef updates an existing ref in a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#update-a-reference
|
||||||
|
func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, ref *Reference, force bool) (*Reference, *Response, error) {
|
||||||
|
refPath := strings.TrimPrefix(*ref.Ref, "refs/")
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refPath)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, &updateRefRequest{
|
||||||
|
SHA: ref.Object.SHA,
|
||||||
|
Force: &force,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := new(Reference)
|
||||||
|
resp, err := s.client.Do(ctx, req, r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRef deletes a ref from a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference
|
||||||
|
func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) {
|
||||||
|
ref = strings.TrimPrefix(ref, "refs/")
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tag represents a tag object.
|
||||||
|
type Tag struct {
|
||||||
|
Tag *string `json:"tag,omitempty"`
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
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
|
||||||
|
// identical to Tag with the exception that the object SHA and Type are
|
||||||
|
// top-level fields, rather than being nested inside a JSON object.
|
||||||
|
type createTagRequest struct {
|
||||||
|
Tag *string `json:"tag,omitempty"`
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
Object *string `json:"object,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
Tagger *CommitAuthor `json:"tagger,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/tags/%v", owner, repo, sha)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := new(Tag)
|
||||||
|
resp, err := s.client.Do(ctx, req, tag)
|
||||||
|
return tag, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTag creates a tag object.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/tags/#create-a-tag-object
|
||||||
|
func (s *GitService) CreateTag(ctx context.Context, owner string, repo string, tag *Tag) (*Tag, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/tags", owner, repo)
|
||||||
|
|
||||||
|
// convert Tag into a createTagRequest
|
||||||
|
tagRequest := &createTagRequest{
|
||||||
|
Tag: tag.Tag,
|
||||||
|
Message: tag.Message,
|
||||||
|
Tagger: tag.Tagger,
|
||||||
|
}
|
||||||
|
if tag.Object != nil {
|
||||||
|
tagRequest.Object = tag.Object.SHA
|
||||||
|
tagRequest.Type = tag.Object.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("POST", u, tagRequest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
t := new(Tag)
|
||||||
|
resp, err := s.client.Do(ctx, req, t)
|
||||||
|
return t, resp, err
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tree represents a GitHub tree.
|
||||||
|
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 {
|
||||||
|
return Stringify(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TreeEntry represents the contents of a tree structure. TreeEntry can
|
||||||
|
// represent either a blob, a commit (in the case of a submodule), or another
|
||||||
|
// tree.
|
||||||
|
type TreeEntry struct {
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
Path *string `json:"path,omitempty"`
|
||||||
|
Mode *string `json:"mode,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
Content *string `json:"content,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TreeEntry) String() string {
|
||||||
|
return Stringify(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTree fetches the Tree object for a given sha hash from a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/trees/#get-a-tree
|
||||||
|
func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha)
|
||||||
|
if recursive {
|
||||||
|
u += "?recursive=1"
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
t := new(Tree)
|
||||||
|
resp, err := s.client.Do(ctx, req, t)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createTree represents the body of a CreateTree request.
|
||||||
|
type createTree struct {
|
||||||
|
BaseTree string `json:"base_tree,omitempty"`
|
||||||
|
Entries []TreeEntry `json:"tree"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTree creates a new tree in a repository. If both a tree and a nested
|
||||||
|
// path modifying that tree are specified, it will overwrite the contents of
|
||||||
|
// that tree with the new path contents and write a new tree out.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/git/trees/#create-a-tree
|
||||||
|
func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo)
|
||||||
|
|
||||||
|
body := &createTree{
|
||||||
|
BaseTree: baseTree,
|
||||||
|
Entries: entries,
|
||||||
|
}
|
||||||
|
req, err := s.client.NewRequest("POST", u, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
t := new(Tree)
|
||||||
|
resp, err := s.client.Do(ctx, req, t)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t, resp, nil
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,64 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitignoresService provides access to the gitignore related functions in the
|
||||||
|
// GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gitignore/
|
||||||
|
type GitignoresService service
|
||||||
|
|
||||||
|
// Gitignore represents a .gitignore file as returned by the GitHub API.
|
||||||
|
type Gitignore struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Source *string `json:"source,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Gitignore) String() string {
|
||||||
|
return Stringify(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List all available Gitignore templates.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gitignore/#listing-available-templates
|
||||||
|
func (s GitignoresService) List(ctx context.Context) ([]string, *Response, error) {
|
||||||
|
req, err := s.client.NewRequest("GET", "gitignore/templates", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var availableTemplates []string
|
||||||
|
resp, err := s.client.Do(ctx, req, &availableTemplates)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableTemplates, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a Gitignore by name.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/gitignore/#get-a-single-template
|
||||||
|
func (s GitignoresService) Get(ctx context.Context, name string) (*Gitignore, *Response, error) {
|
||||||
|
u := fmt.Sprintf("gitignore/templates/%v", name)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
gitignore := new(Gitignore)
|
||||||
|
resp, err := s.client.Do(ctx, req, gitignore)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gitignore, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,347 @@
|
||||||
|
// 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"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssuesService handles communication with the issue related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/
|
||||||
|
type IssuesService service
|
||||||
|
|
||||||
|
// Issue represents a GitHub issue on a repository.
|
||||||
|
//
|
||||||
|
// Note: As far as the GitHub API is concerned, every pull request is an issue,
|
||||||
|
// but not every issue is a pull request. Some endpoints, events, and webhooks
|
||||||
|
// may also return pull requests via this struct. If PullRequestLinks is nil,
|
||||||
|
// 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 *int64 `json:"id,omitempty"`
|
||||||
|
Number *int `json:"number,omitempty"`
|
||||||
|
State *string `json:"state,omitempty"`
|
||||||
|
Locked *bool `json:"locked,omitempty"`
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
Body *string `json:"body,omitempty"`
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
Labels []Label `json:"labels,omitempty"`
|
||||||
|
Assignee *User `json:"assignee,omitempty"`
|
||||||
|
Comments *int `json:"comments,omitempty"`
|
||||||
|
ClosedAt *time.Time `json:"closed_at,omitempty"`
|
||||||
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||||
|
ClosedBy *User `json:"closed_by,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
CommentsURL *string `json:"comments_url,omitempty"`
|
||||||
|
EventsURL *string `json:"events_url,omitempty"`
|
||||||
|
LabelsURL *string `json:"labels_url,omitempty"`
|
||||||
|
RepositoryURL *string `json:"repository_url,omitempty"`
|
||||||
|
Milestone *Milestone `json:"milestone,omitempty"`
|
||||||
|
PullRequestLinks *PullRequestLinks `json:"pull_request,omitempty"`
|
||||||
|
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 {
|
||||||
|
return Stringify(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPullRequest reports whether the issue is also a pull request. It uses the
|
||||||
|
// method recommended by GitHub's API documentation, which is to check whether
|
||||||
|
// PullRequestLinks is non-nil.
|
||||||
|
func (i Issue) IsPullRequest() bool {
|
||||||
|
return i.PullRequestLinks != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueRequest represents a request to create/edit an issue.
|
||||||
|
// It is separate from Issue above because otherwise Labels
|
||||||
|
// and Assignee fail to serialize to the correct JSON.
|
||||||
|
type IssueRequest struct {
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
Body *string `json:"body,omitempty"`
|
||||||
|
Labels *[]string `json:"labels,omitempty"`
|
||||||
|
Assignee *string `json:"assignee,omitempty"`
|
||||||
|
State *string `json:"state,omitempty"`
|
||||||
|
Milestone *int `json:"milestone,omitempty"`
|
||||||
|
Assignees *[]string `json:"assignees,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueListOptions specifies the optional parameters to the IssuesService.List
|
||||||
|
// and IssuesService.ListByOrg methods.
|
||||||
|
type IssueListOptions struct {
|
||||||
|
// Filter specifies which issues to list. Possible values are: assigned,
|
||||||
|
// created, mentioned, subscribed, all. Default is "assigned".
|
||||||
|
Filter string `url:"filter,omitempty"`
|
||||||
|
|
||||||
|
// State filters issues based on their state. Possible values are: open,
|
||||||
|
// closed, all. Default is "open".
|
||||||
|
State string `url:"state,omitempty"`
|
||||||
|
|
||||||
|
// Labels filters issues based on their label.
|
||||||
|
Labels []string `url:"labels,comma,omitempty"`
|
||||||
|
|
||||||
|
// Sort specifies how to sort issues. Possible values are: created, updated,
|
||||||
|
// and comments. Default value is "created".
|
||||||
|
Sort string `url:"sort,omitempty"`
|
||||||
|
|
||||||
|
// Direction in which to sort issues. Possible values are: asc, desc.
|
||||||
|
// Default is "desc".
|
||||||
|
Direction string `url:"direction,omitempty"`
|
||||||
|
|
||||||
|
// Since filters issues by time.
|
||||||
|
Since time.Time `url:"since,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestLinks object is added to the Issue object when it's an issue included
|
||||||
|
// in the IssueCommentEvent webhook payload, if the webhook is fired by a comment on a PR.
|
||||||
|
type PullRequestLinks struct {
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
DiffURL *string `json:"diff_url,omitempty"`
|
||||||
|
PatchURL *string `json:"patch_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List the issues for the authenticated user. If all is true, list issues
|
||||||
|
// across all the user's visible repositories including owned, member, and
|
||||||
|
// organization repositories; if false, list only owned and member
|
||||||
|
// repositories.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues
|
||||||
|
func (s *IssuesService) List(ctx context.Context, all bool, opt *IssueListOptions) ([]*Issue, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if all {
|
||||||
|
u = "issues"
|
||||||
|
} else {
|
||||||
|
u = "user/issues"
|
||||||
|
}
|
||||||
|
return s.listIssues(ctx, u, opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListByOrg fetches the issues in the specified organization for the
|
||||||
|
// authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues
|
||||||
|
func (s *IssuesService) ListByOrg(ctx context.Context, org string, opt *IssueListOptions) ([]*Issue, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/issues", org)
|
||||||
|
return s.listIssues(ctx, u, opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *IssuesService) listIssues(ctx context.Context, u string, opt *IssueListOptions) ([]*Issue, *Response, error) {
|
||||||
|
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 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)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return issues, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueListByRepoOptions specifies the optional parameters to the
|
||||||
|
// IssuesService.ListByRepo method.
|
||||||
|
type IssueListByRepoOptions struct {
|
||||||
|
// Milestone limits issues for the specified milestone. Possible values are
|
||||||
|
// a milestone number, "none" for issues with no milestone, "*" for issues
|
||||||
|
// with any milestone.
|
||||||
|
Milestone string `url:"milestone,omitempty"`
|
||||||
|
|
||||||
|
// State filters issues based on their state. Possible values are: open,
|
||||||
|
// closed, all. Default is "open".
|
||||||
|
State string `url:"state,omitempty"`
|
||||||
|
|
||||||
|
// Assignee filters issues based on their assignee. Possible values are a
|
||||||
|
// user name, "none" for issues that are not assigned, "*" for issues with
|
||||||
|
// any assigned user.
|
||||||
|
Assignee string `url:"assignee,omitempty"`
|
||||||
|
|
||||||
|
// Creator filters issues based on their creator.
|
||||||
|
Creator string `url:"creator,omitempty"`
|
||||||
|
|
||||||
|
// Mentioned filters issues to those mentioned a specific user.
|
||||||
|
Mentioned string `url:"mentioned,omitempty"`
|
||||||
|
|
||||||
|
// Labels filters issues based on their label.
|
||||||
|
Labels []string `url:"labels,omitempty,comma"`
|
||||||
|
|
||||||
|
// Sort specifies how to sort issues. Possible values are: created, updated,
|
||||||
|
// and comments. Default value is "created".
|
||||||
|
Sort string `url:"sort,omitempty"`
|
||||||
|
|
||||||
|
// Direction in which to sort issues. Possible values are: asc, desc.
|
||||||
|
// Default is "desc".
|
||||||
|
Direction string `url:"direction,omitempty"`
|
||||||
|
|
||||||
|
// Since filters issues by time.
|
||||||
|
Since time.Time `url:"since,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListByRepo lists the issues for the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues-for-a-repository
|
||||||
|
func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo string, opt *IssueListByRepoOptions) ([]*Issue, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues", 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 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)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return issues, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#get-a-single-issue
|
||||||
|
func (s *IssuesService) Get(ctx context.Context, owner string, repo string, number int) (*Issue, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return issue, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new issue on the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#create-an-issue
|
||||||
|
func (s *IssuesService) Create(ctx context.Context, owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("POST", u, issue)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return i, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#edit-an-issue
|
||||||
|
func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, issue)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
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, opt *LockIssueOptions) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock an issue's conversation.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/#unlock-an-issue
|
||||||
|
func (s *IssuesService) Unlock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListAssignees fetches all available assignees (owners and collaborators) to
|
||||||
|
// which issues may be assigned.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#list-assignees
|
||||||
|
func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/assignees", 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
|
||||||
|
}
|
||||||
|
var assignees []*User
|
||||||
|
resp, err := s.client.Do(ctx, req, &assignees)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return assignees, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAssignee checks if a user is an assignee for the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#check-assignee
|
||||||
|
func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
resp, err := s.client.Do(ctx, req, nil)
|
||||||
|
assignee, err := parseBoolResponse(err)
|
||||||
|
return assignee, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAssignees adds the provided GitHub users as assignees to the issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
|
||||||
|
func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
|
||||||
|
users := &struct {
|
||||||
|
Assignees []string `json:"assignees,omitempty"`
|
||||||
|
}{Assignees: assignees}
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("POST", u, users)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
issue := &Issue{}
|
||||||
|
resp, err := s.client.Do(ctx, req, issue)
|
||||||
|
return issue, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAssignees removes the provided GitHub users as assignees from the issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
|
||||||
|
func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
|
||||||
|
users := &struct {
|
||||||
|
Assignees []string `json:"assignees,omitempty"`
|
||||||
|
}{Assignees: assignees}
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, users)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
issue := &Issue{}
|
||||||
|
resp, err := s.client.Do(ctx, req, issue)
|
||||||
|
return issue, resp, err
|
||||||
|
}
|
|
@ -0,0 +1,153 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueComment represents a comment left on an issue.
|
||||||
|
type IssueComment struct {
|
||||||
|
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"`
|
||||||
|
// 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 {
|
||||||
|
return Stringify(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueListCommentsOptions specifies the optional parameters to the
|
||||||
|
// IssuesService.ListComments method.
|
||||||
|
type IssueListCommentsOptions struct {
|
||||||
|
// Sort specifies how to sort comments. Possible values are: created, updated.
|
||||||
|
Sort string `url:"sort,omitempty"`
|
||||||
|
|
||||||
|
// Direction in which to sort comments. Possible values are: asc, desc.
|
||||||
|
Direction string `url:"direction,omitempty"`
|
||||||
|
|
||||||
|
// Since filters comments by time.
|
||||||
|
Since time.Time `url:"since,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListComments lists all comments on the specified issue. Specifying an issue
|
||||||
|
// number of 0 will return all comments on all issues for the repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
|
||||||
|
func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opt *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if number == 0 {
|
||||||
|
u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
|
||||||
|
} else {
|
||||||
|
u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
|
||||||
|
}
|
||||||
|
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", mediaTypeReactionsPreview)
|
||||||
|
|
||||||
|
var comments []*IssueComment
|
||||||
|
resp, err := s.client.Do(ctx, req, &comments)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return comments, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, 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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches.
|
||||||
|
req.Header.Set("Accept", mediaTypeReactionsPreview)
|
||||||
|
|
||||||
|
comment := new(IssueComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, comment)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return comment, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateComment creates a new comment on the specified issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/comments/#create-a-comment
|
||||||
|
func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("POST", u, comment)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
c := new(IssueComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, 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
|
||||||
|
}
|
||||||
|
c := new(IssueComment)
|
||||||
|
resp, err := s.client.Do(ctx, req, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, 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
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,161 @@
|
||||||
|
// Copyright 2014 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueEvent represents an event that occurred around an Issue or Pull Request.
|
||||||
|
type IssueEvent struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
|
||||||
|
// The User that generated this event.
|
||||||
|
Actor *User `json:"actor,omitempty"`
|
||||||
|
|
||||||
|
// Event identifies the actual type of Event that occurred. Possible
|
||||||
|
// values are:
|
||||||
|
//
|
||||||
|
// closed
|
||||||
|
// The Actor closed the issue.
|
||||||
|
// If the issue was closed by commit message, CommitID holds the SHA1 hash of the commit.
|
||||||
|
//
|
||||||
|
// merged
|
||||||
|
// The Actor merged into master a branch containing a commit mentioning the issue.
|
||||||
|
// CommitID holds the SHA1 of the merge commit.
|
||||||
|
//
|
||||||
|
// referenced
|
||||||
|
// The Actor committed to master a commit mentioning the issue in its commit message.
|
||||||
|
// CommitID holds the SHA1 of the commit.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// mentioned
|
||||||
|
// Someone unspecified @mentioned the Actor [sic] in an issue comment body.
|
||||||
|
//
|
||||||
|
// assigned, unassigned
|
||||||
|
// The Assigner assigned the issue to or removed the assignment from the Assignee.
|
||||||
|
//
|
||||||
|
// labeled, unlabeled
|
||||||
|
// The Actor added or removed the Label from the issue.
|
||||||
|
//
|
||||||
|
// milestoned, demilestoned
|
||||||
|
// The Actor added or removed the issue from the Milestone.
|
||||||
|
//
|
||||||
|
// subscribed, unsubscribed
|
||||||
|
// The Actor subscribed to or unsubscribed from notifications for an issue.
|
||||||
|
//
|
||||||
|
// head_ref_deleted, head_ref_restored
|
||||||
|
// The pull request’s branch was deleted or restored.
|
||||||
|
//
|
||||||
|
Event *string `json:"event,omitempty"`
|
||||||
|
|
||||||
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
|
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"`
|
||||||
|
LockReason *string `json:"lock_reason,omitempty"`
|
||||||
|
ProjectCard *ProjectCard `json:"project_card,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueEvents lists events for the specified issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-an-issue
|
||||||
|
func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*IssueEvent, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepositoryEvents lists events for the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
||||||
|
func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/events", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var events []*IssueEvent
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 int64) (*IssueEvent, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
event := new(IssueEvent)
|
||||||
|
resp, err := s.client.Do(ctx, req, event)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return event, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename contains details for 'renamed' events.
|
||||||
|
type Rename struct {
|
||||||
|
From *string `json:"from,omitempty"`
|
||||||
|
To *string `json:"to,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Rename) String() string {
|
||||||
|
return Stringify(r)
|
||||||
|
}
|
|
@ -0,0 +1,261 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Label represents a GitHub label on an Issue
|
||||||
|
type Label struct {
|
||||||
|
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 {
|
||||||
|
return Stringify(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListLabels lists all labels for a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
|
||||||
|
func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/labels", 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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
var labels []*Label
|
||||||
|
resp, err := s.client.Do(ctx, req, &labels)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return labels, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLabel gets a single label.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#get-a-single-label
|
||||||
|
func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string, name string) (*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
|
||||||
|
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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
label := new(Label)
|
||||||
|
resp, err := s.client.Do(ctx, req, label)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return label, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabel creates a new label on the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#create-a-label
|
||||||
|
func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo string, label *Label) (*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("POST", u, label)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditLabel edits a label.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#update-a-label
|
||||||
|
func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string, name string, label *Label) (*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, label)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLabel deletes a label.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#delete-a-label
|
||||||
|
func (s *IssuesService) DeleteLabel(ctx context.Context, owner string, repo string, name string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListLabelsByIssue lists all labels for an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
|
||||||
|
func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
|
||||||
|
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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
var labels []*Label
|
||||||
|
resp, err := s.client.Do(ctx, req, &labels)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return labels, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLabelsToIssue adds labels to an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
|
||||||
|
func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("POST", u, labels)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLabelForIssue removes a label for an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
|
||||||
|
func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels/%v", owner, repo, number, label)
|
||||||
|
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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReplaceLabelsForIssue replaces all labels for an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
|
||||||
|
func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("PUT", u, labels)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLabelsForIssue removes all labels for an issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue
|
||||||
|
func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string, repo string, number int) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
|
||||||
|
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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListLabelsForMilestone lists labels for every issue in a milestone.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
|
||||||
|
func (s *IssuesService) ListLabelsForMilestone(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number)
|
||||||
|
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", mediaTypeLabelDescriptionSearchPreview)
|
||||||
|
|
||||||
|
var labels []*Label
|
||||||
|
resp, err := s.client.Do(ctx, req, &labels)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return labels, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,148 @@
|
||||||
|
// Copyright 2014 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Milestone represents a GitHub repository milestone.
|
||||||
|
type Milestone struct {
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
LabelsURL *string `json:"labels_url,omitempty"`
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
Number *int `json:"number,omitempty"`
|
||||||
|
State *string `json:"state,omitempty"`
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Creator *User `json:"creator,omitempty"`
|
||||||
|
OpenIssues *int `json:"open_issues,omitempty"`
|
||||||
|
ClosedIssues *int `json:"closed_issues,omitempty"`
|
||||||
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
|
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 {
|
||||||
|
return Stringify(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MilestoneListOptions specifies the optional parameters to the
|
||||||
|
// IssuesService.ListMilestones method.
|
||||||
|
type MilestoneListOptions struct {
|
||||||
|
// State filters milestones based on their state. Possible values are:
|
||||||
|
// open, closed, all. Default is "open".
|
||||||
|
State string `url:"state,omitempty"`
|
||||||
|
|
||||||
|
// Sort specifies how to sort milestones. Possible values are: due_on, completeness.
|
||||||
|
// Default value is "due_on".
|
||||||
|
Sort string `url:"sort,omitempty"`
|
||||||
|
|
||||||
|
// Direction in which to sort milestones. Possible values are: asc, desc.
|
||||||
|
// Default is "asc".
|
||||||
|
Direction string `url:"direction,omitempty"`
|
||||||
|
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMilestones lists all milestones for a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
|
||||||
|
func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opt *MilestoneListOptions) ([]*Milestone, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones", 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var milestones []*Milestone
|
||||||
|
resp, err := s.client.Do(ctx, req, &milestones)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return milestones, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMilestone gets a single milestone.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
|
||||||
|
func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := s.client.Do(ctx, req, milestone)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return milestone, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMilestone creates a new milestone on the specified repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#create-a-milestone
|
||||||
|
func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("POST", u, milestone)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(Milestone)
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestone edits a milestone.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#update-a-milestone
|
||||||
|
func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, milestone)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(Milestone)
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMilestone deletes a milestone.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#delete-a-milestone
|
||||||
|
func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
|
||||||
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -0,0 +1,149 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Timeline represents an event that occurred around an Issue or Pull Request.
|
||||||
|
//
|
||||||
|
// 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 *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
CommitURL *string `json:"commit_url,omitempty"`
|
||||||
|
|
||||||
|
// The User object that generated the event.
|
||||||
|
Actor *User `json:"actor,omitempty"`
|
||||||
|
|
||||||
|
// Event identifies the actual type of Event that occurred. Possible values
|
||||||
|
// are:
|
||||||
|
//
|
||||||
|
// assigned
|
||||||
|
// The issue was assigned to the assignee.
|
||||||
|
//
|
||||||
|
// closed
|
||||||
|
// The issue was closed by the actor. When the commit_id is present, it
|
||||||
|
// identifies the commit that closed the issue using "closes / fixes #NN"
|
||||||
|
// syntax.
|
||||||
|
//
|
||||||
|
// commented
|
||||||
|
// A comment was added to the issue.
|
||||||
|
//
|
||||||
|
// committed
|
||||||
|
// A commit was added to the pull request's 'HEAD' branch. Only provided
|
||||||
|
// for pull requests.
|
||||||
|
//
|
||||||
|
// cross-referenced
|
||||||
|
// The issue was referenced from another issue. The 'source' attribute
|
||||||
|
// contains the 'id', 'actor', and 'url' of the reference's source.
|
||||||
|
//
|
||||||
|
// demilestoned
|
||||||
|
// The issue was removed from a milestone.
|
||||||
|
//
|
||||||
|
// head_ref_deleted
|
||||||
|
// The pull request's branch was deleted.
|
||||||
|
//
|
||||||
|
// head_ref_restored
|
||||||
|
// The pull request's branch was restored.
|
||||||
|
//
|
||||||
|
// labeled
|
||||||
|
// A label was added to the issue.
|
||||||
|
//
|
||||||
|
// locked
|
||||||
|
// The issue was locked by the actor.
|
||||||
|
//
|
||||||
|
// mentioned
|
||||||
|
// The actor was @mentioned in an issue body.
|
||||||
|
//
|
||||||
|
// merged
|
||||||
|
// The issue was merged by the actor. The 'commit_id' attribute is the
|
||||||
|
// SHA1 of the HEAD commit that was merged.
|
||||||
|
//
|
||||||
|
// milestoned
|
||||||
|
// The issue was added to a milestone.
|
||||||
|
//
|
||||||
|
// referenced
|
||||||
|
// The issue was referenced from a commit message. The 'commit_id'
|
||||||
|
// attribute is the commit SHA1 of where that happened.
|
||||||
|
//
|
||||||
|
// renamed
|
||||||
|
// The issue title was changed.
|
||||||
|
//
|
||||||
|
// reopened
|
||||||
|
// The issue was reopened by the actor.
|
||||||
|
//
|
||||||
|
// subscribed
|
||||||
|
// The actor subscribed to receive notifications for an issue.
|
||||||
|
//
|
||||||
|
// unassigned
|
||||||
|
// The assignee was unassigned from the issue.
|
||||||
|
//
|
||||||
|
// unlabeled
|
||||||
|
// A label was removed from the issue.
|
||||||
|
//
|
||||||
|
// unlocked
|
||||||
|
// The issue was unlocked by the actor.
|
||||||
|
//
|
||||||
|
// unsubscribed
|
||||||
|
// The actor unsubscribed to stop receiving notifications for an issue.
|
||||||
|
//
|
||||||
|
Event *string `json:"event,omitempty"`
|
||||||
|
|
||||||
|
// The string SHA of a commit that referenced this Issue or Pull Request.
|
||||||
|
CommitID *string `json:"commit_id,omitempty"`
|
||||||
|
// The timestamp indicating when the event occurred.
|
||||||
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
|
// The Label object including `name` and `color` attributes. Only provided for
|
||||||
|
// 'labeled' and 'unlabeled' events.
|
||||||
|
Label *Label `json:"label,omitempty"`
|
||||||
|
// The User object which was assigned to (or unassigned from) this Issue or
|
||||||
|
// Pull Request. Only provided for 'assigned' and 'unassigned' events.
|
||||||
|
Assignee *User `json:"assignee,omitempty"`
|
||||||
|
// The Milestone object including a 'title' attribute.
|
||||||
|
// Only provided for 'milestoned' and 'demilestoned' events.
|
||||||
|
Milestone *Milestone `json:"milestone,omitempty"`
|
||||||
|
// The 'id', 'actor', and 'url' for the source of a reference from another issue.
|
||||||
|
// Only provided for 'cross-referenced' events.
|
||||||
|
Source *Source `json:"source,omitempty"`
|
||||||
|
// An object containing rename details including 'from' and 'to' attributes.
|
||||||
|
// Only provided for 'renamed' events.
|
||||||
|
Rename *Rename `json:"rename,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Source represents a reference's source.
|
||||||
|
type Source struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Actor *User `json:"actor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueTimeline lists events for the specified issue.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue
|
||||||
|
func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*Timeline, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number)
|
||||||
|
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", mediaTypeTimelinePreview)
|
||||||
|
|
||||||
|
var events []*Timeline
|
||||||
|
resp, err := s.client.Do(ctx, req, &events)
|
||||||
|
return events, resp, err
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LicensesService handles communication with the license related
|
||||||
|
// methods of the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/licenses/
|
||||||
|
type LicensesService service
|
||||||
|
|
||||||
|
// RepositoryLicense represents the license for a repository.
|
||||||
|
type RepositoryLicense struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Path *string `json:"path,omitempty"`
|
||||||
|
|
||||||
|
SHA *string `json:"sha,omitempty"`
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
GitURL *string `json:"git_url,omitempty"`
|
||||||
|
DownloadURL *string `json:"download_url,omitempty"`
|
||||||
|
Type *string `json:"type,omitempty"`
|
||||||
|
Content *string `json:"content,omitempty"`
|
||||||
|
Encoding *string `json:"encoding,omitempty"`
|
||||||
|
License *License `json:"license,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l RepositoryLicense) String() string {
|
||||||
|
return Stringify(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// License represents an open source license.
|
||||||
|
type License struct {
|
||||||
|
Key *string `json:"key,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
|
||||||
|
SPDXID *string `json:"spdx_id,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
Featured *bool `json:"featured,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Implementation *string `json:"implementation,omitempty"`
|
||||||
|
Permissions *[]string `json:"permissions,omitempty"`
|
||||||
|
Conditions *[]string `json:"conditions,omitempty"`
|
||||||
|
Limitations *[]string `json:"limitations,omitempty"`
|
||||||
|
Body *string `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l License) String() string {
|
||||||
|
return Stringify(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List popular open source licenses.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses
|
||||||
|
func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
|
||||||
|
req, err := s.client.NewRequest("GET", "licenses", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var licenses []*License
|
||||||
|
resp, err := s.client.Do(ctx, req, &licenses)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return licenses, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get extended metadata for one license.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/licenses/#get-an-individual-license
|
||||||
|
func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) {
|
||||||
|
u := fmt.Sprintf("licenses/%s", licenseName)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
license := new(License)
|
||||||
|
resp, err := s.client.Do(ctx, req, license)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return license, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,248 @@
|
||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
// This file provides functions for validating payloads from GitHub Webhooks.
|
||||||
|
// GitHub API docs: https://developer.github.com/webhooks/securing/#validating-payloads-from-github
|
||||||
|
|
||||||
|
package github
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"hash"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// sha1Prefix is the prefix used by GitHub before the HMAC hexdigest.
|
||||||
|
sha1Prefix = "sha1"
|
||||||
|
// sha256Prefix and sha512Prefix are provided for future compatibility.
|
||||||
|
sha256Prefix = "sha256"
|
||||||
|
sha512Prefix = "sha512"
|
||||||
|
// signatureHeader is the GitHub header key used to pass the HMAC hexdigest.
|
||||||
|
signatureHeader = "X-Hub-Signature"
|
||||||
|
// eventTypeHeader is the GitHub header key used to pass the event type.
|
||||||
|
eventTypeHeader = "X-Github-Event"
|
||||||
|
// deliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event.
|
||||||
|
deliveryIDHeader = "X-Github-Delivery"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// eventTypeMapping maps webhooks types to their corresponding go-github struct types.
|
||||||
|
eventTypeMapping = map[string]string{
|
||||||
|
"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",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// genMAC generates the HMAC signature for a message provided the secret key
|
||||||
|
// and hashFunc.
|
||||||
|
func genMAC(message, key []byte, hashFunc func() hash.Hash) []byte {
|
||||||
|
mac := hmac.New(hashFunc, key)
|
||||||
|
mac.Write(message)
|
||||||
|
return mac.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkMAC reports whether messageMAC is a valid HMAC tag for message.
|
||||||
|
func checkMAC(message, messageMAC, key []byte, hashFunc func() hash.Hash) bool {
|
||||||
|
expectedMAC := genMAC(message, key, hashFunc)
|
||||||
|
return hmac.Equal(messageMAC, expectedMAC)
|
||||||
|
}
|
||||||
|
|
||||||
|
// messageMAC returns the hex-decoded HMAC tag from the signature and its
|
||||||
|
// corresponding hash function.
|
||||||
|
func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
|
||||||
|
if signature == "" {
|
||||||
|
return nil, nil, errors.New("missing signature")
|
||||||
|
}
|
||||||
|
sigParts := strings.SplitN(signature, "=", 2)
|
||||||
|
if len(sigParts) != 2 {
|
||||||
|
return nil, nil, fmt.Errorf("error parsing signature %q", signature)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hashFunc func() hash.Hash
|
||||||
|
switch sigParts[0] {
|
||||||
|
case sha1Prefix:
|
||||||
|
hashFunc = sha1.New
|
||||||
|
case sha256Prefix:
|
||||||
|
hashFunc = sha256.New
|
||||||
|
case sha512Prefix:
|
||||||
|
hashFunc = sha512.New
|
||||||
|
default:
|
||||||
|
return nil, nil, fmt.Errorf("unknown hash type prefix: %q", sigParts[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, err := hex.DecodeString(sigParts[1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("error decoding signature %q: %v", signature, err)
|
||||||
|
}
|
||||||
|
return buf, hashFunc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatePayload validates an incoming GitHub Webhook event request
|
||||||
|
// and returns the (JSON) payload.
|
||||||
|
// The Content-Type header of the payload can be "application/json" or "application/x-www-form-urlencoded".
|
||||||
|
// If the Content-Type is neither then an error is returned.
|
||||||
|
// secretKey is the GitHub Webhook secret message.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// func (s *GitHubEventMonitor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// payload, err := github.ValidatePayload(r, s.webhookSecretKey)
|
||||||
|
// if err != nil { ... }
|
||||||
|
// // Process payload...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
func ValidatePayload(r *http.Request, secretKey []byte) (payload []byte, err error) {
|
||||||
|
var body []byte // Raw body that GitHub uses to calculate the signature.
|
||||||
|
|
||||||
|
switch ct := r.Header.Get("Content-Type"); ct {
|
||||||
|
case "application/json":
|
||||||
|
var err error
|
||||||
|
if body, err = ioutil.ReadAll(r.Body); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the content type is application/json,
|
||||||
|
// the JSON payload is just the original body.
|
||||||
|
payload = body
|
||||||
|
|
||||||
|
case "application/x-www-form-urlencoded":
|
||||||
|
// payloadFormParam is the name of the form parameter that the JSON payload
|
||||||
|
// will be in if a webhook has its content type set to application/x-www-form-urlencoded.
|
||||||
|
const payloadFormParam = "payload"
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if body, err = ioutil.ReadAll(r.Body); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the content type is application/x-www-form-urlencoded,
|
||||||
|
// the JSON payload will be under the "payload" form param.
|
||||||
|
form, err := url.ParseQuery(string(body))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
payload = []byte(form.Get(payloadFormParam))
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Webhook request has unsupported Content-Type %q", ct)
|
||||||
|
}
|
||||||
|
|
||||||
|
sig := r.Header.Get(signatureHeader)
|
||||||
|
if err := ValidateSignature(sig, body, secretKey); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return payload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
messageMAC, hashFunc, err := messageMAC(signature)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !checkMAC(payload, messageMAC, secretKey, hashFunc) {
|
||||||
|
return errors.New("payload signature check failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebHookType returns the event type of webhook request r.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers
|
||||||
|
func WebHookType(r *http.Request) string {
|
||||||
|
return r.Header.Get(eventTypeHeader)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeliveryID returns the unique delivery ID of webhook request r.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers
|
||||||
|
func DeliveryID(r *http.Request) string {
|
||||||
|
return r.Header.Get(deliveryIDHeader)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseWebHook parses the event payload. For recognized event types, a
|
||||||
|
// value of the corresponding struct type will be returned (as returned
|
||||||
|
// by Event.ParsePayload()). An error will be returned for unrecognized event
|
||||||
|
// types.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// func (s *GitHubEventMonitor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// payload, err := github.ValidatePayload(r, s.webhookSecretKey)
|
||||||
|
// if err != nil { ... }
|
||||||
|
// event, err := github.ParseWebHook(github.WebHookType(r), payload)
|
||||||
|
// if err != nil { ... }
|
||||||
|
// switch event := event.(type) {
|
||||||
|
// case *github.CommitCommentEvent:
|
||||||
|
// processCommitCommentEvent(event)
|
||||||
|
// case *github.CreateEvent:
|
||||||
|
// processCreateEvent(event)
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
func ParseWebHook(messageType string, payload []byte) (interface{}, error) {
|
||||||
|
eventType, ok := eventTypeMapping[messageType]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unknown X-Github-Event in message: %v", messageType)
|
||||||
|
}
|
||||||
|
|
||||||
|
event := Event{
|
||||||
|
Type: &eventType,
|
||||||
|
RawPayload: (*json.RawMessage)(&payload),
|
||||||
|
}
|
||||||
|
return event.ParsePayload()
|
||||||
|
}
|
|
@ -0,0 +1,224 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MigrationService provides access to the migration related functions
|
||||||
|
// in the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/
|
||||||
|
type MigrationService service
|
||||||
|
|
||||||
|
// Migration represents a GitHub migration (archival).
|
||||||
|
type Migration 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 Migration) String() string {
|
||||||
|
return Stringify(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrationOptions specifies the optional parameters to Migration methods.
|
||||||
|
type MigrationOptions 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// startMigration represents the body of a StartMigration request.
|
||||||
|
type startMigration 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartMigration starts the generation of a migration archive.
|
||||||
|
// repos is a slice of repository names to migrate.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#start-a-migration
|
||||||
|
func (s *MigrationService) StartMigration(ctx context.Context, org string, repos []string, opt *MigrationOptions) (*Migration, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/migrations", org)
|
||||||
|
|
||||||
|
body := &startMigration{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 := &Migration{}
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMigrations lists the most recent migrations.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#get-a-list-of-migrations
|
||||||
|
func (s *MigrationService) ListMigrations(ctx context.Context, org string) ([]*Migration, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/migrations", org)
|
||||||
|
|
||||||
|
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 []*Migration
|
||||||
|
resp, err := s.client.Do(ctx, req, &m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrationStatus gets the status of a specific migration archive.
|
||||||
|
// 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 int64) (*Migration, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/migrations/%v", org, 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 := &Migration{}
|
||||||
|
resp, err := s.client.Do(ctx, req, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrationArchiveURL fetches a migration archive URL.
|
||||||
|
// 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 int64) (url string, err error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches.
|
||||||
|
req.Header.Set("Accept", mediaTypeMigrationsPreview)
|
||||||
|
|
||||||
|
s.client.clientMu.Lock()
|
||||||
|
defer s.client.clientMu.Unlock()
|
||||||
|
|
||||||
|
// Disable the redirect mechanism because AWS fails if the GitHub auth token is provided.
|
||||||
|
var loc string
|
||||||
|
saveRedirect := s.client.client.CheckRedirect
|
||||||
|
s.client.client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||||
|
loc = req.URL.String()
|
||||||
|
return errors.New("disable redirect")
|
||||||
|
}
|
||||||
|
defer func() { s.client.client.CheckRedirect = saveRedirect }()
|
||||||
|
|
||||||
|
_, err = s.client.Do(ctx, req, nil) // expect error from disable redirect
|
||||||
|
if err == nil {
|
||||||
|
return "", errors.New("expected redirect, none provided")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "disable redirect") {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return loc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMigration deletes a previous migration archive.
|
||||||
|
// 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 int64) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, 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", mediaTypeMigrationsPreview)
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnlockRepo unlocks a repository that was locked for migration.
|
||||||
|
// id is the 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/migration/migrations/#unlock-a-repository
|
||||||
|
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)
|
||||||
|
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)
|
||||||
|
}
|
329
vendor/github.com/google/go-github/github/migrations_source_import.go
generated
vendored
Normal file
329
vendor/github.com/google/go-github/github/migrations_source_import.go
generated
vendored
Normal file
|
@ -0,0 +1,329 @@
|
||||||
|
// Copyright 2016 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Import represents a repository import request.
|
||||||
|
type Import struct {
|
||||||
|
// The URL of the originating repository.
|
||||||
|
VCSURL *string `json:"vcs_url,omitempty"`
|
||||||
|
// The originating VCS type. Can be one of 'subversion', 'git',
|
||||||
|
// 'mercurial', or 'tfvc'. Without this parameter, the import job will
|
||||||
|
// take additional time to detect the VCS type before beginning the
|
||||||
|
// import. This detection step will be reflected in the response.
|
||||||
|
VCS *string `json:"vcs,omitempty"`
|
||||||
|
// VCSUsername and VCSPassword are only used for StartImport calls that
|
||||||
|
// are importing a password-protected repository.
|
||||||
|
VCSUsername *string `json:"vcs_username,omitempty"`
|
||||||
|
VCSPassword *string `json:"vcs_password,omitempty"`
|
||||||
|
// For a tfvc import, the name of the project that is being imported.
|
||||||
|
TFVCProject *string `json:"tfvc_project,omitempty"`
|
||||||
|
|
||||||
|
// LFS related fields that may be preset in the Import Progress response
|
||||||
|
|
||||||
|
// Describes whether the import has been opted in or out of using Git
|
||||||
|
// LFS. The value can be 'opt_in', 'opt_out', or 'undecided' if no
|
||||||
|
// action has been taken.
|
||||||
|
UseLFS *string `json:"use_lfs,omitempty"`
|
||||||
|
// Describes whether files larger than 100MB were found during the
|
||||||
|
// importing step.
|
||||||
|
HasLargeFiles *bool `json:"has_large_files,omitempty"`
|
||||||
|
// The total size in gigabytes of files larger than 100MB found in the
|
||||||
|
// originating repository.
|
||||||
|
LargeFilesSize *int `json:"large_files_size,omitempty"`
|
||||||
|
// The total number of files larger than 100MB found in the originating
|
||||||
|
// repository. To see a list of these files, call LargeFiles.
|
||||||
|
LargeFilesCount *int `json:"large_files_count,omitempty"`
|
||||||
|
|
||||||
|
// Identifies the current status of an import. An import that does not
|
||||||
|
// have errors will progress through these steps:
|
||||||
|
//
|
||||||
|
// detecting - the "detection" step of the import is in progress
|
||||||
|
// because the request did not include a VCS parameter. The
|
||||||
|
// import is identifying the type of source control present at
|
||||||
|
// the URL.
|
||||||
|
// importing - the "raw" step of the import is in progress. This is
|
||||||
|
// where commit data is fetched from the original repository.
|
||||||
|
// The import progress response will include CommitCount (the
|
||||||
|
// total number of raw commits that will be imported) and
|
||||||
|
// Percent (0 - 100, the current progress through the import).
|
||||||
|
// mapping - the "rewrite" step of the import is in progress. This
|
||||||
|
// is where SVN branches are converted to Git branches, and
|
||||||
|
// where author updates are applied. The import progress
|
||||||
|
// response does not include progress information.
|
||||||
|
// pushing - the "push" step of the import is in progress. This is
|
||||||
|
// where the importer updates the repository on GitHub. The
|
||||||
|
// import progress response will include PushPercent, which is
|
||||||
|
// the percent value reported by git push when it is "Writing
|
||||||
|
// objects".
|
||||||
|
// complete - the import is complete, and the repository is ready
|
||||||
|
// on GitHub.
|
||||||
|
//
|
||||||
|
// If there are problems, you will see one of these in the status field:
|
||||||
|
//
|
||||||
|
// auth_failed - the import requires authentication in order to
|
||||||
|
// connect to the original repository. Make an UpdateImport
|
||||||
|
// request, and include VCSUsername and VCSPassword.
|
||||||
|
// error - the import encountered an error. The import progress
|
||||||
|
// response will include the FailedStep and an error message.
|
||||||
|
// Contact GitHub support for more information.
|
||||||
|
// detection_needs_auth - the importer requires authentication for
|
||||||
|
// the originating repository to continue detection. Make an
|
||||||
|
// UpdatImport request, and include VCSUsername and
|
||||||
|
// VCSPassword.
|
||||||
|
// detection_found_nothing - the importer didn't recognize any
|
||||||
|
// source control at the URL.
|
||||||
|
// detection_found_multiple - the importer found several projects
|
||||||
|
// or repositories at the provided URL. When this is the case,
|
||||||
|
// the Import Progress response will also include a
|
||||||
|
// ProjectChoices field with the possible project choices as
|
||||||
|
// values. Make an UpdateImport request, and include VCS and
|
||||||
|
// (if applicable) TFVCProject.
|
||||||
|
Status *string `json:"status,omitempty"`
|
||||||
|
CommitCount *int `json:"commit_count,omitempty"`
|
||||||
|
StatusText *string `json:"status_text,omitempty"`
|
||||||
|
AuthorsCount *int `json:"authors_count,omitempty"`
|
||||||
|
Percent *int `json:"percent,omitempty"`
|
||||||
|
PushPercent *int `json:"push_percent,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
HTMLURL *string `json:"html_url,omitempty"`
|
||||||
|
AuthorsURL *string `json:"authors_url,omitempty"`
|
||||||
|
RepositoryURL *string `json:"repository_url,omitempty"`
|
||||||
|
Message *string `json:"message,omitempty"`
|
||||||
|
FailedStep *string `json:"failed_step,omitempty"`
|
||||||
|
|
||||||
|
// Human readable display name, provided when the Import appears as
|
||||||
|
// part of ProjectChoices.
|
||||||
|
HumanName *string `json:"human_name,omitempty"`
|
||||||
|
|
||||||
|
// When the importer finds several projects or repositories at the
|
||||||
|
// provided URLs, this will identify the available choices. Call
|
||||||
|
// UpdateImport with the selected Import value.
|
||||||
|
ProjectChoices []Import `json:"project_choices,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Import) String() string {
|
||||||
|
return Stringify(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SourceImportAuthor identifies an author imported from a source repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors
|
||||||
|
type SourceImportAuthor struct {
|
||||||
|
ID *int64 `json:"id,omitempty"`
|
||||||
|
RemoteID *string `json:"remote_id,omitempty"`
|
||||||
|
RemoteName *string `json:"remote_name,omitempty"`
|
||||||
|
Email *string `json:"email,omitempty"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
ImportURL *string `json:"import_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a SourceImportAuthor) String() string {
|
||||||
|
return Stringify(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LargeFile identifies a file larger than 100MB found during a repository import.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files
|
||||||
|
type LargeFile struct {
|
||||||
|
RefName *string `json:"ref_name,omitempty"`
|
||||||
|
Path *string `json:"path,omitempty"`
|
||||||
|
OID *string `json:"oid,omitempty"`
|
||||||
|
Size *int `json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f LargeFile) String() string {
|
||||||
|
return Stringify(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartImport initiates a repository import.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#start-an-import
|
||||||
|
func (s *MigrationService) StartImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("PUT", u, in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches
|
||||||
|
req.Header.Set("Accept", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
out := new(Import)
|
||||||
|
resp, err := s.client.Do(ctx, req, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImportProgress queries for the status and progress of an ongoing repository import.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-import-progress
|
||||||
|
func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo string) (*Import, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
|
||||||
|
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", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
out := new(Import)
|
||||||
|
resp, err := s.client.Do(ctx, req, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateImport initiates a repository import.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#update-existing-import
|
||||||
|
func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches
|
||||||
|
req.Header.Set("Accept", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
out := new(Import)
|
||||||
|
resp, err := s.client.Do(ctx, req, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommitAuthors gets the authors mapped from the original repository.
|
||||||
|
//
|
||||||
|
// Each type of source control system represents authors in a different way.
|
||||||
|
// For example, a Git commit author has a display name and an email address,
|
||||||
|
// but a Subversion commit author just has a username. The GitHub Importer will
|
||||||
|
// make the author information valid, but the author might not be correct. For
|
||||||
|
// example, it will change the bare Subversion username "hubot" into something
|
||||||
|
// like "hubot <hubot@12341234-abab-fefe-8787-fedcba987654>".
|
||||||
|
//
|
||||||
|
// This method and MapCommitAuthor allow you to provide correct Git author
|
||||||
|
// information.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors
|
||||||
|
func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string) ([]*SourceImportAuthor, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import/authors", owner, repo)
|
||||||
|
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", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
var authors []*SourceImportAuthor
|
||||||
|
resp, err := s.client.Do(ctx, req, &authors)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return authors, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCommitAuthor updates an author's identity for the import. Your
|
||||||
|
// application can continue updating authors any time before you push new
|
||||||
|
// 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 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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches
|
||||||
|
req.Header.Set("Accept", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
out := new(SourceImportAuthor)
|
||||||
|
resp, err := s.client.Do(ctx, req, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLFSPreference sets whether imported repositories should use Git LFS for
|
||||||
|
// files larger than 100MB. Only the UseLFS field on the provided Import is
|
||||||
|
// used.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#set-git-lfs-preference
|
||||||
|
func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import/lfs", owner, repo)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches
|
||||||
|
req.Header.Set("Accept", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
out := new(Import)
|
||||||
|
resp, err := s.client.Do(ctx, req, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LargeFiles lists files larger than 100MB found during the import.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files
|
||||||
|
func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) ([]*LargeFile, *Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import/large_files", owner, repo)
|
||||||
|
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", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
var files []*LargeFile
|
||||||
|
resp, err := s.client.Do(ctx, req, &files)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return files, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CancelImport stops an import for a repository.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#cancel-an-import
|
||||||
|
func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) {
|
||||||
|
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
|
||||||
|
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", mediaTypeImportPreview)
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnlockUserRepo 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)
|
||||||
|
}
|
|
@ -0,0 +1,257 @@
|
||||||
|
// Copyright 2014 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 (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarkdownOptions specifies optional parameters to the Markdown method.
|
||||||
|
type MarkdownOptions struct {
|
||||||
|
// Mode identifies the rendering mode. Possible values are:
|
||||||
|
// markdown - render a document as plain Markdown, just like
|
||||||
|
// README files are rendered.
|
||||||
|
//
|
||||||
|
// gfm - to render a document as user-content, e.g. like user
|
||||||
|
// comments or issues are rendered. In GFM mode, hard line breaks are
|
||||||
|
// always taken into account, and issue and user mentions are linked
|
||||||
|
// accordingly.
|
||||||
|
//
|
||||||
|
// Default is "markdown".
|
||||||
|
Mode string
|
||||||
|
|
||||||
|
// Context identifies the repository context. Only taken into account
|
||||||
|
// when rendering as "gfm".
|
||||||
|
Context string
|
||||||
|
}
|
||||||
|
|
||||||
|
type markdownRequest struct {
|
||||||
|
Text *string `json:"text,omitempty"`
|
||||||
|
Mode *string `json:"mode,omitempty"`
|
||||||
|
Context *string `json:"context,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Markdown renders an arbitrary Markdown document.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/markdown/
|
||||||
|
func (c *Client) Markdown(ctx context.Context, text string, opt *MarkdownOptions) (string, *Response, error) {
|
||||||
|
request := &markdownRequest{Text: String(text)}
|
||||||
|
if opt != nil {
|
||||||
|
if opt.Mode != "" {
|
||||||
|
request.Mode = String(opt.Mode)
|
||||||
|
}
|
||||||
|
if opt.Context != "" {
|
||||||
|
request.Context = String(opt.Context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := c.NewRequest("POST", "markdown", request)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
resp, err := c.Do(ctx, req, buf)
|
||||||
|
if err != nil {
|
||||||
|
return "", resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String(), resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEmojis returns the emojis available to use on GitHub.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/emojis/
|
||||||
|
func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) {
|
||||||
|
req, err := c.NewRequest("GET", "emojis", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var emoji map[string]string
|
||||||
|
resp, err := c.Do(ctx, req, &emoji)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return emoji, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CodeOfConduct represents a code of conduct.
|
||||||
|
type CodeOfConduct struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Key *string `json:"key,omitempty"`
|
||||||
|
URL *string `json:"url,omitempty"`
|
||||||
|
Body *string `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CodeOfConduct) String() string {
|
||||||
|
return Stringify(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCodesOfConduct returns all codes of conduct.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct
|
||||||
|
func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
|
||||||
|
req, err := c.NewRequest("GET", "codes_of_conduct", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove custom Accept header when this API fully launches.
|
||||||
|
req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
|
||||||
|
|
||||||
|
var cs []*CodeOfConduct
|
||||||
|
resp, err := c.Do(ctx, req, &cs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cs, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodeOfConduct returns an individual code of conduct.
|
||||||
|
//
|
||||||
|
// https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct
|
||||||
|
func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
|
||||||
|
u := fmt.Sprintf("codes_of_conduct/%s", key)
|
||||||
|
req, err := c.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", mediaTypeCodesOfConductPreview)
|
||||||
|
|
||||||
|
coc := new(CodeOfConduct)
|
||||||
|
resp, err := c.Do(ctx, req, coc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return coc, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIMeta represents metadata about the GitHub API.
|
||||||
|
type APIMeta struct {
|
||||||
|
// An Array of IP addresses in CIDR format specifying the addresses
|
||||||
|
// that incoming service hooks will originate from on GitHub.com.
|
||||||
|
Hooks []string `json:"hooks,omitempty"`
|
||||||
|
|
||||||
|
// An Array of IP addresses in CIDR format specifying the Git servers
|
||||||
|
// for GitHub.com.
|
||||||
|
Git []string `json:"git,omitempty"`
|
||||||
|
|
||||||
|
// Whether authentication with username and password is supported.
|
||||||
|
// (GitHub Enterprise instances using CAS or OAuth for authentication
|
||||||
|
// will return false. Features like Basic Authentication with a
|
||||||
|
// username and password, sudo mode, and two-factor authentication are
|
||||||
|
// not supported on these servers.)
|
||||||
|
VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"`
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// this endpoint on your organization’s GitHub Enterprise installation, this
|
||||||
|
// endpoint provides information about that installation.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/meta/
|
||||||
|
func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
|
||||||
|
req, err := c.NewRequest("GET", "meta", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := new(APIMeta)
|
||||||
|
resp, err := c.Do(ctx, req, meta)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Octocat returns an ASCII art octocat with the specified message in a speech
|
||||||
|
// bubble. If message is empty, a random zen phrase is used.
|
||||||
|
func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) {
|
||||||
|
u := "octocat"
|
||||||
|
if message != "" {
|
||||||
|
u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := c.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
resp, err := c.Do(ctx, req, buf)
|
||||||
|
if err != nil {
|
||||||
|
return "", resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String(), resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zen returns a random line from The Zen of GitHub.
|
||||||
|
//
|
||||||
|
// see also: http://warpspire.com/posts/taste/
|
||||||
|
func (c *Client) Zen(ctx context.Context) (string, *Response, error) {
|
||||||
|
req, err := c.NewRequest("GET", "zen", nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
resp, err := c.Do(ctx, req, buf)
|
||||||
|
if err != nil {
|
||||||
|
return "", resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String(), resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServiceHook represents a hook that has configuration settings, a list of
|
||||||
|
// available events, and default events.
|
||||||
|
type ServiceHook struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Events []string `json:"events,omitempty"`
|
||||||
|
SupportedEvents []string `json:"supported_events,omitempty"`
|
||||||
|
Schema [][]string `json:"schema,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceHook) String() string {
|
||||||
|
return Stringify(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListServiceHooks lists all of the available service hooks.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/webhooks/#services
|
||||||
|
func (c *Client) ListServiceHooks(ctx context.Context) ([]*ServiceHook, *Response, error) {
|
||||||
|
u := "hooks"
|
||||||
|
req, err := c.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var hooks []*ServiceHook
|
||||||
|
resp, err := c.Do(ctx, req, &hooks)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hooks, resp, nil
|
||||||
|
}
|
|
@ -0,0 +1,208 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrganizationsService provides access to the organization related functions
|
||||||
|
// in the GitHub API.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/orgs/
|
||||||
|
type OrganizationsService service
|
||||||
|
|
||||||
|
// Organization represents a GitHub organization account.
|
||||||
|
type Organization struct {
|
||||||
|
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"`
|
||||||
|
EventsURL *string `json:"events_url,omitempty"`
|
||||||
|
HooksURL *string `json:"hooks_url,omitempty"`
|
||||||
|
IssuesURL *string `json:"issues_url,omitempty"`
|
||||||
|
MembersURL *string `json:"members_url,omitempty"`
|
||||||
|
PublicMembersURL *string `json:"public_members_url,omitempty"`
|
||||||
|
ReposURL *string `json:"repos_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Organization) String() string {
|
||||||
|
return Stringify(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plan represents the payment plan for an account. See plans at https://github.com/plans.
|
||||||
|
type Plan struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Space *int `json:"space,omitempty"`
|
||||||
|
Collaborators *int `json:"collaborators,omitempty"`
|
||||||
|
PrivateRepos *int `json:"private_repos,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Plan) String() string {
|
||||||
|
return Stringify(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrganizationsListOptions specifies the optional parameters to the
|
||||||
|
// OrganizationsService.ListAll method.
|
||||||
|
type OrganizationsListOptions struct {
|
||||||
|
// Since filters Organizations by ID.
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAll lists all organizations, in the order that they were created on GitHub.
|
||||||
|
//
|
||||||
|
// Note: Pagination is powered exclusively by the since parameter. To continue
|
||||||
|
// listing the next set of organizations, use the ID of the last-returned organization
|
||||||
|
// as the opts.Since parameter for the next call.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/orgs/#list-all-organizations
|
||||||
|
func (s *OrganizationsService) ListAll(ctx context.Context, opt *OrganizationsListOptions) ([]*Organization, *Response, error) {
|
||||||
|
u, err := addOptions("organizations", opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
orgs := []*Organization{}
|
||||||
|
resp, err := s.client.Do(ctx, req, &orgs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return orgs, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// List the organizations for a user. Passing the empty string will list
|
||||||
|
// organizations for the authenticated user.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/orgs/#list-user-organizations
|
||||||
|
func (s *OrganizationsService) List(ctx context.Context, user string, opt *ListOptions) ([]*Organization, *Response, error) {
|
||||||
|
var u string
|
||||||
|
if user != "" {
|
||||||
|
u = fmt.Sprintf("users/%v/orgs", user)
|
||||||
|
} else {
|
||||||
|
u = "user/orgs"
|
||||||
|
}
|
||||||
|
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 orgs []*Organization
|
||||||
|
resp, err := s.client.Do(ctx, req, &orgs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return orgs, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get fetches an organization by name.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/orgs/#get-an-organization
|
||||||
|
func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v", org)
|
||||||
|
req, err := s.client.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
organization := new(Organization)
|
||||||
|
resp, err := s.client.Do(ctx, req, organization)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return organization, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetByID fetches an organization.
|
||||||
|
//
|
||||||
|
// Note: GetByID uses the undocumented GitHub API endpoint /organizations/:id.
|
||||||
|
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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
organization := new(Organization)
|
||||||
|
resp, err := s.client.Do(ctx, req, organization)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return organization, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit an organization.
|
||||||
|
//
|
||||||
|
// GitHub API docs: https://developer.github.com/v3/orgs/#edit-an-organization
|
||||||
|
func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
|
||||||
|
u := fmt.Sprintf("orgs/%v", name)
|
||||||
|
req, err := s.client.NewRequest("PATCH", u, org)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
o := new(Organization)
|
||||||
|
resp, err := s.client.Do(ctx, req, o)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return o, resp, nil
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue