...

Source file src/github.com/google/go-github/v33/example/migrations/main.go

Documentation: github.com/google/go-github/v33/example/migrations

     1  // Copyright 2018 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  // migrations demonstrates the functionality of
     7  // the user data migration API for the authenticated GitHub
     8  // user and lists all the user migrations.
     9  package main
    10  
    11  import (
    12  	"context"
    13  	"fmt"
    14  
    15  	"github.com/google/go-github/v33/github"
    16  	"golang.org/x/oauth2"
    17  )
    18  
    19  func fetchAllUserMigrations() ([]*github.UserMigration, error) {
    20  	ctx := context.Background()
    21  	ts := oauth2.StaticTokenSource(
    22  		&oauth2.Token{AccessToken: "<GITHUB_AUTH_TOKEN>"},
    23  	)
    24  	tc := oauth2.NewClient(ctx, ts)
    25  	client := github.NewClient(tc)
    26  
    27  	migrations, _, err := client.Migrations.ListUserMigrations(ctx)
    28  	return migrations, err
    29  }
    30  
    31  func main() {
    32  	migrations, err := fetchAllUserMigrations()
    33  	if err != nil {
    34  		fmt.Printf("Error %v\n", err)
    35  		return
    36  	}
    37  
    38  	for i, m := range migrations {
    39  		fmt.Printf("%v. %v", i+1, m.GetID())
    40  	}
    41  }
    42  

View as plain text