Skip to content

Commit

Permalink
Merge pull request #69 from microsoft/dev
Browse files Browse the repository at this point in the history
Merge dev to master for 5.1 version
  • Loading branch information
tedchamb authored May 17, 2020
2 parents 60c61a7 + 5203116 commit ecbcf11
Show file tree
Hide file tree
Showing 136 changed files with 83,458 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Set the default behavior (used when a rule below doesn't match)
* text=auto

# Go files
*.go text eol=lf
*.mod text eol=lf
*.sum text eol=lf

# Some Windows-specific files should always be CRLF
*.bat text eol=crlf

# Shell scripts
*.sh text eol=lf
37 changes: 37 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go
on: [push]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: go build
run: go build -v ./...

- name: go fmt
run: go fmt ./...

- name: go vet
run: go vet ./...

- name: go test
run: go test ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.idea/
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
[![Go](https://github.com/microsoft/azure-devops-go-api/workflows/Go/badge.svg)](https://github.com/microsoft/azure-devops-go-api/actions)
[![Build Status](https://dev.azure.com/mseng/vsts-cli/_apis/build/status/microsoft.azure-devops-go-api?branchName=dev)](https://dev.azure.com/mseng/vsts-cli/_build/latest?definitionId=9110&branchName=dev)
[![Go Report Card](https://goreportcard.com/badge/github.com/microsoft/azure-devops-go-api)](https://goreportcard.com/report/github.com/microsoft/azure-devops-go-api)

# Azure DevOps Go API
This repository contains Go APIs for interacting with and managing Azure DevOps.

## Get started
To use the API, establish a connection using a [personal access token](https://docs.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops) and the URL to your Azure DevOps organization. Then get a client using the connection and make API calls.

```
package main
import (
"context"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/microsoft/azure-devops-go-api/azuredevops/core"
"log"
)
func main() {
organizationUrl := "https://dev.azure.com/myorg" // todo: replace value with your organization url
personalAccessToken := "XXXXXXXXXXXXXXXXXXXXXXX" // todo: replace value with your PAT
// Create a connection to your organization
connection := azuredevops.NewPatConnection(organizationUrl, personalAccessToken)
ctx := context.Background()
// Create a client to interact with the Core area
coreClient, err := core.NewClient(ctx, connection)
if err != nil {
log.Fatal(err)
}
// Get first page of the list of team projects for your organization
responseValue, err := coreClient.GetProjects(ctx, core.GetProjectsArgs{})
if err != nil {
log.Fatal(err)
}
index := 0
for responseValue != nil {
// Log the page of team project names
for _, teamProjectReference := range (*responseValue).Value {
log.Printf("Name[%v] = %v", index, *teamProjectReference.Name)
index++
}
// if continuationToken has a value, then there is at least one more page of projects to get
if responseValue.ContinuationToken != "" {
// Get next page of team projects
projectArgs := core.GetProjectsArgs{
ContinuationToken: &responseValue.ContinuationToken,
}
responseValue, err = coreClient.GetProjects(ctx, projectArgs)
if err != nil {
log.Fatal(err)
}
} else {
responseValue = nil
}
}
}
```

## API documentation

This Go library provides a thin wrapper around the Azure DevOps REST APIs. See the [Azure DevOps REST API reference](https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1) for details on calling different APIs.


# Contributing

Expand Down
48 changes: 48 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Go
# Build your Go project.
# Add steps that test, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/go

trigger:
- master
- dev

pool:
vmImage: 'ubuntu-latest'

variables:
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)' # Path to the module's code

steps:
- script: |
printenv | sort
displayName: 'Log Environment Variables'

- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'

- script: |
go version
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
go build -v ./...
workingDirectory: '$(modulePath)'
displayName: 'Get dependencies, then build'

- script: |
go test ./...
workingDirectory: '$(modulePath)'
displayName: 'Run unit tests'
71 changes: 71 additions & 0 deletions azuredevops/accounts/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------------------------
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// --------------------------------------------------------------------------------------------

package accounts

import (
"context"
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"net/http"
"net/url"
)

var ResourceAreaId, _ = uuid.Parse("0d55247a-1c47-4462-9b1f-5e2125590ee6")

type Client interface {
// Get a list of accounts for a specific owner or a specific member.
GetAccounts(context.Context, GetAccountsArgs) (*[]Account, error)
}

type ClientImpl struct {
Client azuredevops.Client
}

func NewClient(ctx context.Context, connection *azuredevops.Connection) (Client, error) {
client, err := connection.GetClientByResourceAreaId(ctx, ResourceAreaId)
if err != nil {
return nil, err
}
return &ClientImpl{
Client: *client,
}, nil
}

// Get a list of accounts for a specific owner or a specific member.
func (client *ClientImpl) GetAccounts(ctx context.Context, args GetAccountsArgs) (*[]Account, error) {
queryParams := url.Values{}
if args.OwnerId != nil {
queryParams.Add("ownerId", (*args.OwnerId).String())
}
if args.MemberId != nil {
queryParams.Add("memberId", (*args.MemberId).String())
}
if args.Properties != nil {
queryParams.Add("properties", *args.Properties)
}
locationId, _ := uuid.Parse("229a6a53-b428-4ffb-a835-e8f36b5b4b1e")
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1", nil, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}

var responseValue []Account
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}

// Arguments for the GetAccounts function
type GetAccountsArgs struct {
// (optional) ID for the owner of the accounts.
OwnerId *uuid.UUID
// (optional) ID for a member of the accounts.
MemberId *uuid.UUID
// (optional)
Properties *string
}
124 changes: 124 additions & 0 deletions azuredevops/accounts/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------------------------
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// --------------------------------------------------------------------------------------------

package accounts

import (
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops"
)

type Account struct {
// Identifier for an Account
AccountId *uuid.UUID `json:"accountId,omitempty"`
// Name for an account
AccountName *string `json:"accountName,omitempty"`
// Owner of account
AccountOwner *uuid.UUID `json:"accountOwner,omitempty"`
// Current account status
AccountStatus *AccountStatus `json:"accountStatus,omitempty"`
// Type of account: Personal, Organization
AccountType *AccountType `json:"accountType,omitempty"`
// Uri for an account
AccountUri *string `json:"accountUri,omitempty"`
// Who created the account
CreatedBy *uuid.UUID `json:"createdBy,omitempty"`
// Date account was created
CreatedDate *azuredevops.Time `json:"createdDate,omitempty"`
HasMoved *bool `json:"hasMoved,omitempty"`
// Identity of last person to update the account
LastUpdatedBy *uuid.UUID `json:"lastUpdatedBy,omitempty"`
// Date account was last updated
LastUpdatedDate *azuredevops.Time `json:"lastUpdatedDate,omitempty"`
// Namespace for an account
NamespaceId *uuid.UUID `json:"namespaceId,omitempty"`
NewCollectionId *uuid.UUID `json:"newCollectionId,omitempty"`
// Organization that created the account
OrganizationName *string `json:"organizationName,omitempty"`
// Extended properties
Properties interface{} `json:"properties,omitempty"`
// Reason for current status
StatusReason *string `json:"statusReason,omitempty"`
}

type AccountCreateInfoInternal struct {
AccountName *string `json:"accountName,omitempty"`
Creator *uuid.UUID `json:"creator,omitempty"`
Organization *string `json:"organization,omitempty"`
Preferences *AccountPreferencesInternal `json:"preferences,omitempty"`
Properties interface{} `json:"properties,omitempty"`
ServiceDefinitions *[]azuredevops.KeyValuePair `json:"serviceDefinitions,omitempty"`
}

type AccountPreferencesInternal struct {
Culture interface{} `json:"culture,omitempty"`
Language interface{} `json:"language,omitempty"`
TimeZone interface{} `json:"timeZone,omitempty"`
}

type AccountStatus string

type accountStatusValuesType struct {
None AccountStatus
Enabled AccountStatus
Disabled AccountStatus
Deleted AccountStatus
Moved AccountStatus
}

var AccountStatusValues = accountStatusValuesType{
None: "none",
// This hosting account is active and assigned to a customer.
Enabled: "enabled",
// This hosting account is disabled.
Disabled: "disabled",
// This account is part of deletion batch and scheduled for deletion.
Deleted: "deleted",
// This account is not mastered locally and has physically moved.
Moved: "moved",
}

type AccountType string

type accountTypeValuesType struct {
Personal AccountType
Organization AccountType
}

var AccountTypeValues = accountTypeValuesType{
Personal: "personal",
Organization: "organization",
}

type AccountUserStatus string

type accountUserStatusValuesType struct {
None AccountUserStatus
Active AccountUserStatus
Disabled AccountUserStatus
Deleted AccountUserStatus
Pending AccountUserStatus
Expired AccountUserStatus
PendingDisabled AccountUserStatus
}

var AccountUserStatusValues = accountUserStatusValuesType{
None: "none",
// User has signed in at least once to the VSTS account
Active: "active",
// User cannot sign in; primarily used by admin to temporarily remove a user due to absence or license reallocation
Disabled: "disabled",
// User is removed from the VSTS account by the VSTS account admin
Deleted: "deleted",
// User is invited to join the VSTS account by the VSTS account admin, but has not signed up/signed in yet
Pending: "pending",
// User can sign in; primarily used when license is in expired state and we give a grace period
Expired: "expired",
// User is disabled; if reenabled, they will still be in the Pending state
PendingDisabled: "pendingDisabled",
}
Loading

0 comments on commit ecbcf11

Please sign in to comment.