From 9901531729c02affad935da5e6f74e83829e2999 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Thu, 28 Sep 2017 22:51:12 +0200
Subject: [PATCH 01/12] #720 Initial commit for listing Plans and Plan Accounts
 * Includes basic testing for Listing Plans and the Accounts linked to a Plan
 (including stubs)

---
 github/apps_marketplace.go      | 109 ++++++++++++++++++++++++++++++++
 github/apps_marketplace_test.go |  84 ++++++++++++++++++++++++
 github/github.go                |   5 ++
 3 files changed, 198 insertions(+)
 create mode 100644 github/apps_marketplace.go
 create mode 100644 github/apps_marketplace_test.go

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
new file mode 100644
index 00000000000..776846125f0
--- /dev/null
+++ b/github/apps_marketplace.go
@@ -0,0 +1,109 @@
+// 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"
+)
+
+// MarketplaceService handles communication with the marketplace related
+// methods of the GitHub API.
+//
+// GitHub API docs: https://developer.github.com/v3/apps/marketplace/
+type MarketplaceService service
+
+// MarketplacePlan represents a GitHub Apps Marketplace Listing Plan.
+type MarketplacePlan struct {
+	URL                 *string   `json:"url"`
+	AccountsURL         *string   `json:"accounts_url"`
+	ID                  *int      `json:"id"`
+	Name                *string   `json:"name"`
+	Description         *string   `json:"description"`
+	MonthlyPriceInCents *int      `json:"monthly_price_in_cents"`
+	YearlyPriceInCents  *int      `json:"yearly_price_in_cents"`
+	PriceModel          *string   `json:"price_model"`
+	UnitName            *string   `json:"unit_name"`
+	Bullets             *[]string `json:"bullets"`
+}
+
+// MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
+type MarketplacePurchase struct {
+	BillingCycle    *string          `json:"billing_cycle"`
+	NextBillingDate *string          `json:"next_billing_date"`
+	UnitCount       *int             `json:"unit_count"`
+	Plan            *MarketplacePlan `json:"plan"`
+}
+
+// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan
+type MarketplacePlanAccount struct {
+	URL                      *string              `json:"url"`
+	AccountType              *string              `json:"type"`
+	ID                       *int                 `json:"id"`
+	Login                    *string              `json:"login"`
+	Email                    *string              `json:"email"`
+	OrganizationBillingEmail *string              `json:"organization_billing_email"`
+	MarketplacePurchase      *MarketplacePurchase `json:"marketplace_purchase"`
+}
+
+// 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, stubbed bool, opt *ListOptions) ([]*MarketplacePlan, *Response, error) {
+	u, err := addOptions(fmt.Sprintf("%v/plans", marketplaceURI(stubbed)), 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", mediaTypeMarketplacePreview)
+
+	var i []*MarketplacePlan
+	resp, err := s.client.Do(ctx, req, &i)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return i, resp, nil
+}
+
+// ListPlanAccounts 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) ListPlanAccounts(ctx context.Context, planID int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
+	u, err := addOptions(fmt.Sprintf("%v/plans/%v/accounts", marketplaceURI(stubbed), planID), 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", mediaTypeMarketplacePreview)
+
+	var i []*MarketplacePlanAccount
+	resp, err := s.client.Do(ctx, req, &i)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return i, resp, nil
+}
+
+func marketplaceURI(stubbed bool) string {
+	if stubbed {
+		return "apps/marketplace_listing/stubbed"
+	}
+	return "apps/marketplace_listing"
+}
diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go
new file mode 100644
index 00000000000..45988b03d5b
--- /dev/null
+++ b/github/apps_marketplace_test.go
@@ -0,0 +1,84 @@
+// 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"
+	"net/http"
+	"reflect"
+	"testing"
+)
+
+func TestMarketplaceService_ListPlans(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/apps/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		testFormValues(t, r, values{
+			"page":     "1",
+			"per_page": "2",
+		})
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	plans, _, err := client.Marketplace.ListPlans(context.Background(), false, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlans returned error: %v", err)
+	}
+
+	want := []*MarketplacePlan{{ID: Int(1)}}
+	if !reflect.DeepEqual(plans, want) {
+		t.Errorf("Marketplace.ListPlans returned %+v, want %+v", plans, want)
+	}
+}
+
+func TestMarketplaceService_ListPlansStubbed(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/apps/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	plans, _, err := client.Marketplace.ListPlans(context.Background(), true, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlans returned error: %v", err)
+	}
+
+	want := []*MarketplacePlan{{ID: Int(1)}}
+	if !reflect.DeepEqual(plans, want) {
+		t.Errorf("Marketplace.ListPlans returned %+v, want %+v", plans, want)
+	}
+}
+
+func TestMarketplaceService_ListPlanAccounts(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/apps/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	accounts, _, err := client.Marketplace.ListPlanAccounts(context.Background(), 1, false, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlanAccounts returned error: %v", err)
+	}
+
+	want := []*MarketplacePlanAccount{{ID: Int(1)}}
+	if !reflect.DeepEqual(accounts, want) {
+		t.Errorf("Marketplace.ListPlanAccounts returned %+v, want %+v", accounts, want)
+	}
+}
diff --git a/github/github.go b/github/github.go
index 99ad8d078d0..52fc5390aa5 100644
--- a/github/github.go
+++ b/github/github.go
@@ -102,6 +102,9 @@ const (
 
 	// https://developer.github.com/changes/2017-07-26-team-review-request-thor-preview/
 	mediaTypeTeamReviewPreview = "application/vnd.github.thor-preview+json"
+
+	// https://developer.github.com/v3/apps/marketplace/
+	mediaTypeMarketplacePreview = "application/vnd.github.valkyrie-preview+json"
 )
 
 // A Client manages communication with the GitHub API.
@@ -143,6 +146,7 @@ type Client struct {
 	Licenses       *LicensesService
 	Migrations     *MigrationService
 	Reactions      *ReactionsService
+	Marketplace    *MarketplaceService
 }
 
 type service struct {
@@ -224,6 +228,7 @@ func NewClient(httpClient *http.Client) *Client {
 	c.Gitignores = (*GitignoresService)(&c.common)
 	c.Issues = (*IssuesService)(&c.common)
 	c.Licenses = (*LicensesService)(&c.common)
+	c.Marketplace = (*MarketplaceService)(&c.common)
 	c.Migrations = (*MigrationService)(&c.common)
 	c.Organizations = (*OrganizationsService)(&c.common)
 	c.Projects = (*ProjectsService)(&c.common)

From 9157290fc9e60030b24dfa374536d249eb10158d Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Thu, 28 Sep 2017 23:52:14 +0200
Subject: [PATCH 02/12] Added the fullstops and omitempty to maintain
 consistency

---
 github/apps_marketplace.go | 48 +++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index 776846125f0..03c9c7da62b 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -18,38 +18,38 @@ type MarketplaceService service
 
 // MarketplacePlan represents a GitHub Apps Marketplace Listing Plan.
 type MarketplacePlan struct {
-	URL                 *string   `json:"url"`
-	AccountsURL         *string   `json:"accounts_url"`
-	ID                  *int      `json:"id"`
-	Name                *string   `json:"name"`
-	Description         *string   `json:"description"`
-	MonthlyPriceInCents *int      `json:"monthly_price_in_cents"`
-	YearlyPriceInCents  *int      `json:"yearly_price_in_cents"`
-	PriceModel          *string   `json:"price_model"`
-	UnitName            *string   `json:"unit_name"`
-	Bullets             *[]string `json:"bullets"`
+	URL                 *string   `json:"url,omitempty"`
+	AccountsURL         *string   `json:"accounts_url,omitempty"`
+	ID                  *int      `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"`
+	PriceModel          *string   `json:"price_model,omitempty"`
+	UnitName            *string   `json:"unit_name,omitempty"`
+	Bullets             *[]string `json:"bullets,omitempty"`
 }
 
 // MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
 type MarketplacePurchase struct {
-	BillingCycle    *string          `json:"billing_cycle"`
-	NextBillingDate *string          `json:"next_billing_date"`
-	UnitCount       *int             `json:"unit_count"`
-	Plan            *MarketplacePlan `json:"plan"`
+	BillingCycle    *string          `json:"billing_cycle,omitempty"`
+	NextBillingDate *string          `json:"next_billing_date,omitempty"`
+	UnitCount       *int             `json:"unit_count,omitempty"`
+	Plan            *MarketplacePlan `json:"plan,omitempty"`
 }
 
-// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan
+// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan.
 type MarketplacePlanAccount struct {
-	URL                      *string              `json:"url"`
-	AccountType              *string              `json:"type"`
-	ID                       *int                 `json:"id"`
-	Login                    *string              `json:"login"`
-	Email                    *string              `json:"email"`
-	OrganizationBillingEmail *string              `json:"organization_billing_email"`
-	MarketplacePurchase      *MarketplacePurchase `json:"marketplace_purchase"`
+	URL                      *string              `json:"url,omitempty"`
+	AccountType              *string              `json:"type,omitempty"`
+	ID                       *int                 `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"`
 }
 
-// ListPlans lists all plans for your Marketplace listing
+// 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, stubbed bool, opt *ListOptions) ([]*MarketplacePlan, *Response, error) {
@@ -75,7 +75,7 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, stubbed bool, opt *L
 	return i, resp, nil
 }
 
-// ListPlanAccounts lists all GitHub accounts (user or organization) on a specific plan
+// ListPlanAccounts 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) ListPlanAccounts(ctx context.Context, planID int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {

From 2fb48331a7e73b0fd561208e0bd85840ec1e17d9 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Sun, 1 Oct 2017 18:38:20 +0200
Subject: [PATCH 03/12] Added remaining functionality along with basic tests

---
 github/apps_marketplace.go      | 65 ++++++++++++++++++++++++++++++---
 github/apps_marketplace_test.go | 52 ++++++++++++++++++++++++--
 2 files changed, 107 insertions(+), 10 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index 03c9c7da62b..f5890ca870a 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -32,10 +32,11 @@ type MarketplacePlan struct {
 
 // MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
 type MarketplacePurchase struct {
-	BillingCycle    *string          `json:"billing_cycle,omitempty"`
-	NextBillingDate *string          `json:"next_billing_date,omitempty"`
-	UnitCount       *int             `json:"unit_count,omitempty"`
-	Plan            *MarketplacePlan `json:"plan,omitempty"`
+	BillingCycle           *string                 `json:"billing_cycle,omitempty"`
+	NextBillingDate        *string                 `json:"next_billing_date,omitempty"`
+	UnitCount              *int                    `json:"unit_count,omitempty"`
+	Plan                   *MarketplacePlan        `json:"plan,omitempty"`
+	MarketplacePlanAccount *MarketplacePlanAccount `json:"account,omitempty"`
 }
 
 // MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan.
@@ -75,10 +76,10 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, stubbed bool, opt *L
 	return i, resp, nil
 }
 
-// ListPlanAccounts lists all GitHub accounts (user or organization) on a specific plan.
+// 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) ListPlanAccounts(ctx context.Context, planID int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
+func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
 	u, err := addOptions(fmt.Sprintf("%v/plans/%v/accounts", marketplaceURI(stubbed), planID), opt)
 	if err != nil {
 		return nil, nil, err
@@ -101,6 +102,58 @@ func (s *MarketplaceService) ListPlanAccounts(ctx context.Context, planID int, s
 	return i, 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 int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
+	u, err := addOptions(fmt.Sprintf("%v/accounts/%v", marketplaceURI(stubbed), accountID), 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", mediaTypeMarketplacePreview)
+
+	var i []*MarketplacePlanAccount
+	resp, err := s.client.Do(ctx, req, &i)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return i, 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, stubbed bool, opt *ListOptions) ([]*MarketplacePurchase, *Response, error) {
+	u, err := addOptions("apps/user/marketplace_purchases", 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", mediaTypeMarketplacePreview)
+
+	var i []*MarketplacePurchase
+	resp, err := s.client.Do(ctx, req, &i)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return i, resp, nil
+}
+
 func marketplaceURI(stubbed bool) string {
 	if stubbed {
 		return "apps/marketplace_listing/stubbed"
diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go
index 45988b03d5b..b51034b3722 100644
--- a/github/apps_marketplace_test.go
+++ b/github/apps_marketplace_test.go
@@ -61,7 +61,7 @@ func TestMarketplaceService_ListPlansStubbed(t *testing.T) {
 	}
 }
 
-func TestMarketplaceService_ListPlanAccounts(t *testing.T) {
+func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) {
 	setup()
 	defer teardown()
 
@@ -72,13 +72,57 @@ func TestMarketplaceService_ListPlanAccounts(t *testing.T) {
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	accounts, _, err := client.Marketplace.ListPlanAccounts(context.Background(), 1, false, opt)
+	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, false, opt)
 	if err != nil {
-		t.Errorf("Marketplace.ListPlanAccounts returned error: %v", err)
+		t.Errorf("Marketplace.ListPlanAccountsForPlan returned error: %v", err)
 	}
 
 	want := []*MarketplacePlanAccount{{ID: Int(1)}}
 	if !reflect.DeepEqual(accounts, want) {
-		t.Errorf("Marketplace.ListPlanAccounts returned %+v, want %+v", accounts, want)
+		t.Errorf("Marketplace.ListPlanAccountsForPlan returned %+v, want %+v", accounts, want)
+	}
+}
+
+func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/apps/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, false, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err)
+	}
+
+	want := []*MarketplacePlanAccount{{ID: Int(1)}}
+	if !reflect.DeepEqual(accounts, want) {
+		t.Errorf("Marketplace.ListPlanAccountsForAccount returned %+v, want %+v", accounts, want)
+	}
+}
+
+func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/apps/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), false, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err)
+	}
+
+	want := []*MarketplacePurchase{{BillingCycle: String("monthly")}}
+	if !reflect.DeepEqual(purchases, want) {
+		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want)
 	}
 }

From 6ac3c7e7769444ba9cc316b6c5a51aac74864af3 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Mon, 2 Oct 2017 06:50:37 +0200
Subject: [PATCH 04/12] Run go generate to gen accessor methods for
 Marketplace* struct fields

---
 github/github-accessors.go | 152 +++++++++++++++++++++++++++++++++++++
 1 file changed, 152 insertions(+)

diff --git a/github/github-accessors.go b/github/github-accessors.go
index 4fed8e50a62..72ed1b6665b 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -2588,6 +2588,158 @@ func (m *markdownRequest) GetText() string {
 	return *m.Text
 }
 
+// GetAccountsURL returns the AccountsURL field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetAccountsURL() string {
+	if m == nil || m.AccountsURL == nil {
+		return ""
+	}
+	return *m.AccountsURL
+}
+
+// GetBullets returns the Bullets field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetBullets() []string {
+	if m == nil || m.Bullets == nil {
+		return nil
+	}
+	return *m.Bullets
+}
+
+// GetDescription returns the Description field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetDescription() string {
+	if m == nil || m.Description == nil {
+		return ""
+	}
+	return *m.Description
+}
+
+// GetID returns the ID field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetID() int {
+	if m == nil || m.ID == nil {
+		return 0
+	}
+	return *m.ID
+}
+
+// GetMonthlyPriceInCents returns the MonthlyPriceInCents field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetMonthlyPriceInCents() int {
+	if m == nil || m.MonthlyPriceInCents == nil {
+		return 0
+	}
+	return *m.MonthlyPriceInCents
+}
+
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetName() string {
+	if m == nil || m.Name == nil {
+		return ""
+	}
+	return *m.Name
+}
+
+// GetPriceModel returns the PriceModel field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetPriceModel() string {
+	if m == nil || m.PriceModel == nil {
+		return ""
+	}
+	return *m.PriceModel
+}
+
+// GetUnitName returns the UnitName field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetUnitName() string {
+	if m == nil || m.UnitName == nil {
+		return ""
+	}
+	return *m.UnitName
+}
+
+// GetURL returns the URL field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetURL() string {
+	if m == nil || m.URL == nil {
+		return ""
+	}
+	return *m.URL
+}
+
+// GetYearlyPriceInCents returns the YearlyPriceInCents field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlan) GetYearlyPriceInCents() int {
+	if m == nil || m.YearlyPriceInCents == nil {
+		return 0
+	}
+	return *m.YearlyPriceInCents
+}
+
+// GetAccountType returns the AccountType field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetAccountType() string {
+	if m == nil || m.AccountType == nil {
+		return ""
+	}
+	return *m.AccountType
+}
+
+// GetEmail returns the Email field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetEmail() string {
+	if m == nil || m.Email == nil {
+		return ""
+	}
+	return *m.Email
+}
+
+// GetID returns the ID field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetID() int {
+	if m == nil || m.ID == nil {
+		return 0
+	}
+	return *m.ID
+}
+
+// GetLogin returns the Login field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetLogin() string {
+	if m == nil || m.Login == nil {
+		return ""
+	}
+	return *m.Login
+}
+
+// GetOrganizationBillingEmail returns the OrganizationBillingEmail field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetOrganizationBillingEmail() string {
+	if m == nil || m.OrganizationBillingEmail == nil {
+		return ""
+	}
+	return *m.OrganizationBillingEmail
+}
+
+// GetURL returns the URL field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetURL() string {
+	if m == nil || m.URL == nil {
+		return ""
+	}
+	return *m.URL
+}
+
+// GetBillingCycle returns the BillingCycle field if it's non-nil, zero value otherwise.
+func (m *MarketplacePurchase) GetBillingCycle() string {
+	if m == nil || m.BillingCycle == nil {
+		return ""
+	}
+	return *m.BillingCycle
+}
+
+// GetNextBillingDate returns the NextBillingDate field if it's non-nil, zero value otherwise.
+func (m *MarketplacePurchase) GetNextBillingDate() string {
+	if m == nil || m.NextBillingDate == nil {
+		return ""
+	}
+	return *m.NextBillingDate
+}
+
+// GetUnitCount returns the UnitCount field if it's non-nil, zero value otherwise.
+func (m *MarketplacePurchase) GetUnitCount() int {
+	if m == nil || m.UnitCount == nil {
+		return 0
+	}
+	return *m.UnitCount
+}
+
 // GetText returns the Text field if it's non-nil, zero value otherwise.
 func (m *Match) GetText() string {
 	if m == nil || m.Text == nil {

From 6c4b54e9e03fbc1f7be2de6849dc6f500686fec4 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Sun, 22 Oct 2017 12:19:40 +0200
Subject: [PATCH 05/12] Added Stubbed tests and switched MarketplaceService to
 use struct instead of service

Added a flag, `stubbed` to the MarketplaceService struct to set whether or not the Service should called the stubbed endpoints
---
 github/apps_marketplace.go      |  46 ++++++++++-----
 github/apps_marketplace_test.go | 100 +++++++++++++++++++++++++++-----
 github/github.go                |   2 +-
 3 files changed, 121 insertions(+), 27 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index f5890ca870a..86bed85c50b 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -14,7 +14,18 @@ import (
 // methods of the GitHub API.
 //
 // GitHub API docs: https://developer.github.com/v3/apps/marketplace/
-type MarketplaceService service
+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
+
+	ListOptions
+}
 
 // MarketplacePlan represents a GitHub Apps Marketplace Listing Plan.
 type MarketplacePlan struct {
@@ -53,8 +64,9 @@ type MarketplacePlanAccount struct {
 // 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, stubbed bool, opt *ListOptions) ([]*MarketplacePlan, *Response, error) {
-	u, err := addOptions(fmt.Sprintf("%v/plans", marketplaceURI(stubbed)), opt)
+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
 	}
@@ -79,8 +91,9 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, stubbed bool, opt *L
 // 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 int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
-	u, err := addOptions(fmt.Sprintf("%v/plans/%v/accounts", marketplaceURI(stubbed), planID), opt)
+func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int, 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
 	}
@@ -105,8 +118,9 @@ func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID
 // 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 int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
-	u, err := addOptions(fmt.Sprintf("%v/accounts/%v", marketplaceURI(stubbed), accountID), opt)
+func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, accountID int, 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
 	}
@@ -131,8 +145,13 @@ func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, acc
 // 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, stubbed bool, opt *ListOptions) ([]*MarketplacePurchase, *Response, error) {
-	u, err := addOptions("apps/user/marketplace_purchases", opt)
+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
 	}
@@ -154,9 +173,10 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context
 	return i, resp, nil
 }
 
-func marketplaceURI(stubbed bool) string {
-	if stubbed {
-		return "apps/marketplace_listing/stubbed"
+func (s *MarketplaceService) marketplaceURI(endpoint string) string {
+	url := "marketplace_listing"
+	if s.Stubbed {
+		url = "marketplace_listing/stubbed"
 	}
-	return "apps/marketplace_listing"
+	return url + "/" + endpoint
 }
diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go
index b51034b3722..f62be146843 100644
--- a/github/apps_marketplace_test.go
+++ b/github/apps_marketplace_test.go
@@ -17,7 +17,7 @@ func TestMarketplaceService_ListPlans(t *testing.T) {
 	setup()
 	defer teardown()
 
-	mux.HandleFunc("/apps/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
 		testFormValues(t, r, values{
@@ -28,7 +28,8 @@ func TestMarketplaceService_ListPlans(t *testing.T) {
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	plans, _, err := client.Marketplace.ListPlans(context.Background(), false, opt)
+	client.Marketplace.Stubbed = false
+	plans, _, err := client.Marketplace.ListPlans(context.Background(), opt)
 	if err != nil {
 		t.Errorf("Marketplace.ListPlans returned error: %v", err)
 	}
@@ -39,25 +40,26 @@ func TestMarketplaceService_ListPlans(t *testing.T) {
 	}
 }
 
-func TestMarketplaceService_ListPlansStubbed(t *testing.T) {
+func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) {
 	setup()
 	defer teardown()
 
-	mux.HandleFunc("/apps/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
 		fmt.Fprint(w, `[{"id":1}]`)
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	plans, _, err := client.Marketplace.ListPlans(context.Background(), true, opt)
+	client.Marketplace.Stubbed = true
+	plans, _, err := client.Marketplace.ListPlans(context.Background(), opt)
 	if err != nil {
-		t.Errorf("Marketplace.ListPlans returned error: %v", err)
+		t.Errorf("Marketplace.ListPlans (Stubbed) returned error: %v", err)
 	}
 
 	want := []*MarketplacePlan{{ID: Int(1)}}
 	if !reflect.DeepEqual(plans, want) {
-		t.Errorf("Marketplace.ListPlans returned %+v, want %+v", plans, want)
+		t.Errorf("Marketplace.ListPlans (Stubbed) returned %+v, want %+v", plans, want)
 	}
 }
 
@@ -65,14 +67,15 @@ func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) {
 	setup()
 	defer teardown()
 
-	mux.HandleFunc("/apps/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
 		fmt.Fprint(w, `[{"id":1}]`)
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, false, opt)
+	client.Marketplace.Stubbed = false
+	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt)
 	if err != nil {
 		t.Errorf("Marketplace.ListPlanAccountsForPlan returned error: %v", err)
 	}
@@ -83,18 +86,42 @@ func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) {
 	}
 }
 
+func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/marketplace_listing/stubbed/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	client.Marketplace.Stubbed = true
+	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned error: %v", err)
+	}
+
+	want := []*MarketplacePlanAccount{{ID: Int(1)}}
+	if !reflect.DeepEqual(accounts, want) {
+		t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned %+v, want %+v", accounts, want)
+	}
+}
+
 func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
 	setup()
 	defer teardown()
 
-	mux.HandleFunc("/apps/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
 		fmt.Fprint(w, `[{"id":1}]`)
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, false, opt)
+	client.Marketplace.Stubbed = false
+	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt)
 	if err != nil {
 		t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err)
 	}
@@ -105,18 +132,65 @@ func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
 	}
 }
 
+func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/marketplace_listing/stubbed/accounts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"id":1}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	client.Marketplace.Stubbed = true
+	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned error: %v", err)
+	}
+
+	want := []*MarketplacePlanAccount{{ID: Int(1)}}
+	if !reflect.DeepEqual(accounts, want) {
+		t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned %+v, want %+v", accounts, want)
+	}
+}
+
 func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) {
 	setup()
 	defer teardown()
 
-	mux.HandleFunc("/apps/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
+		fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`)
+	})
+
+	opt := &ListOptions{Page: 1, PerPage: 2}
+	client.Marketplace.Stubbed = false
+	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt)
+	if err != nil {
+		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err)
+	}
+
+	want := []*MarketplacePurchase{{BillingCycle: String("monthly")}}
+	if !reflect.DeepEqual(purchases, want) {
+		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want)
+	}
+}
+
+func TestMarketplaceService_Stubbed_ListMarketplacePurchasesForUser(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/user/marketplace_purchases/stubbed", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", mediaTypeMarketplacePreview)
 		fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`)
 	})
 
 	opt := &ListOptions{Page: 1, PerPage: 2}
-	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), false, opt)
+	client.Marketplace.Stubbed = true
+	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt)
 	if err != nil {
 		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err)
 	}
diff --git a/github/github.go b/github/github.go
index 52fc5390aa5..3de2938b525 100644
--- a/github/github.go
+++ b/github/github.go
@@ -228,7 +228,7 @@ func NewClient(httpClient *http.Client) *Client {
 	c.Gitignores = (*GitignoresService)(&c.common)
 	c.Issues = (*IssuesService)(&c.common)
 	c.Licenses = (*LicensesService)(&c.common)
-	c.Marketplace = (*MarketplaceService)(&c.common)
+	c.Marketplace = &MarketplaceService{client: c}
 	c.Migrations = (*MigrationService)(&c.common)
 	c.Organizations = (*OrganizationsService)(&c.common)
 	c.Projects = (*ProjectsService)(&c.common)

From bb51e74b303cf93fcb2635b3749afe6af6c8a00d Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Tue, 24 Oct 2017 08:19:23 +0200
Subject: [PATCH 06/12] Removed unused field

---
 github/apps_marketplace.go | 2 --
 1 file changed, 2 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index 86bed85c50b..4027b698cd7 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -23,8 +23,6 @@ type MarketplaceService struct {
 	//
 	// GitHub API docs: https://developer.github.com/v3/apps/marketplace/
 	Stubbed bool
-
-	ListOptions
 }
 
 // MarketplacePlan represents a GitHub Apps Marketplace Listing Plan.

From 354464dd638b2ad7ce19ba627c69a9d3a5623abe Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Tue, 31 Oct 2017 20:52:24 +0100
Subject: [PATCH 07/12] Made the chanegs suggested by @gmlewis

---
 github/apps_marketplace.go      | 40 ++++++++++++++++-----------------
 github/apps_marketplace_test.go |  2 +-
 github/github-accessors.go      | 16 ++++++-------
 github/github.go                |  2 +-
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index 4027b698cd7..adda5126693 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -1,4 +1,4 @@
-// Copyright 2013 The go-github AUTHORS. All rights reserved.
+// 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.
@@ -20,8 +20,6 @@ type MarketplaceService struct {
 	// 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
 }
 
@@ -41,17 +39,17 @@ type MarketplacePlan struct {
 
 // MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
 type MarketplacePurchase struct {
-	BillingCycle           *string                 `json:"billing_cycle,omitempty"`
-	NextBillingDate        *string                 `json:"next_billing_date,omitempty"`
-	UnitCount              *int                    `json:"unit_count,omitempty"`
-	Plan                   *MarketplacePlan        `json:"plan,omitempty"`
-	MarketplacePlanAccount *MarketplacePlanAccount `json:"account,omitempty"`
+	BillingCycle    *string                 `json:"billing_cycle,omitempty"`
+	NextBillingDate *string                 `json:"next_billing_date,omitempty"`
+	UnitCount       *int                    `json:"unit_count,omitempty"`
+	Plan            *MarketplacePlan        `json:"plan,omitempty"`
+	Account         *MarketplacePlanAccount `json:"account,omitempty"`
 }
 
 // MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan.
 type MarketplacePlanAccount struct {
 	URL                      *string              `json:"url,omitempty"`
-	AccountType              *string              `json:"type,omitempty"`
+	Type                     *string              `json:"type,omitempty"`
 	ID                       *int                 `json:"id,omitempty"`
 	Login                    *string              `json:"login,omitempty"`
 	Email                    *string              `json:"email,omitempty"`
@@ -77,13 +75,13 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, opt *ListOptions) ([
 	// TODO: remove custom Accept header when this API fully launches.
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
-	var i []*MarketplacePlan
-	resp, err := s.client.Do(ctx, req, &i)
+	var plans []*MarketplacePlan
+	resp, err := s.client.Do(ctx, req, &plans)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return i, resp, nil
+	return plans, resp, nil
 }
 
 // ListPlanAccountsForPlan lists all GitHub accounts (user or organization) on a specific plan.
@@ -104,13 +102,13 @@ func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID
 	// TODO: remove custom Accept header when this API fully launches.
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
-	var i []*MarketplacePlanAccount
-	resp, err := s.client.Do(ctx, req, &i)
+	var accounts []*MarketplacePlanAccount
+	resp, err := s.client.Do(ctx, req, &accounts)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return i, resp, nil
+	return accounts, resp, nil
 }
 
 // ListPlanAccountsForAccount lists all GitHub accounts (user or organization) associated with an account.
@@ -131,13 +129,13 @@ func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, acc
 	// TODO: remove custom Accept header when this API fully launches.
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
-	var i []*MarketplacePlanAccount
-	resp, err := s.client.Do(ctx, req, &i)
+	var accounts []*MarketplacePlanAccount
+	resp, err := s.client.Do(ctx, req, &accounts)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return i, resp, nil
+	return accounts, resp, nil
 }
 
 // ListMarketplacePurchasesForUser lists all GitHub marketplace purchases made by a user.
@@ -162,13 +160,13 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context
 	// TODO: remove custom Accept header when this API fully launches.
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
-	var i []*MarketplacePurchase
-	resp, err := s.client.Do(ctx, req, &i)
+	var purchaces []*MarketplacePurchase
+	resp, err := s.client.Do(ctx, req, &purchases)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return i, resp, nil
+	return purchases, resp, nil
 }
 
 func (s *MarketplaceService) marketplaceURI(endpoint string) string {
diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go
index f62be146843..151a72179cb 100644
--- a/github/apps_marketplace_test.go
+++ b/github/apps_marketplace_test.go
@@ -1,4 +1,4 @@
-// Copyright 2013 The go-github AUTHORS. All rights reserved.
+// 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.
diff --git a/github/github-accessors.go b/github/github-accessors.go
index bea31bb721e..e3805c0e10a 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -2772,14 +2772,6 @@ func (m *MarketplacePlan) GetYearlyPriceInCents() int {
 	return *m.YearlyPriceInCents
 }
 
-// GetAccountType returns the AccountType field if it's non-nil, zero value otherwise.
-func (m *MarketplacePlanAccount) GetAccountType() string {
-	if m == nil || m.AccountType == nil {
-		return ""
-	}
-	return *m.AccountType
-}
-
 // GetEmail returns the Email field if it's non-nil, zero value otherwise.
 func (m *MarketplacePlanAccount) GetEmail() string {
 	if m == nil || m.Email == nil {
@@ -2812,6 +2804,14 @@ func (m *MarketplacePlanAccount) GetOrganizationBillingEmail() string {
 	return *m.OrganizationBillingEmail
 }
 
+// GetType returns the Type field if it's non-nil, zero value otherwise.
+func (m *MarketplacePlanAccount) GetType() string {
+	if m == nil || m.Type == nil {
+		return ""
+	}
+	return *m.Type
+}
+
 // GetURL returns the URL field if it's non-nil, zero value otherwise.
 func (m *MarketplacePlanAccount) GetURL() string {
 	if m == nil || m.URL == nil {
diff --git a/github/github.go b/github/github.go
index 5251aa609a2..90e96bd271e 100644
--- a/github/github.go
+++ b/github/github.go
@@ -147,9 +147,9 @@ type Client struct {
 	Search         *SearchService
 	Users          *UsersService
 	Licenses       *LicensesService
+	Marketplace    *MarketplaceService
 	Migrations     *MigrationService
 	Reactions      *ReactionsService
-	Marketplace    *MarketplaceService
 }
 
 type service struct {

From 46617e6d0ff34603202f234b81aaa51caf878b12 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Tue, 31 Oct 2017 20:59:53 +0100
Subject: [PATCH 08/12] Incorrectly named variable.

---
 github/apps_marketplace.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index adda5126693..d927b4a1849 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -161,12 +161,12 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
 	var purchaces []*MarketplacePurchase
-	resp, err := s.client.Do(ctx, req, &purchases)
+	resp, err := s.client.Do(ctx, req, &purchaces)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return purchases, resp, nil
+	return purchaces, resp, nil
 }
 
 func (s *MarketplaceService) marketplaceURI(endpoint string) string {

From c4466d172dda0c36b848f44fdb1a30ccb8b851d0 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Tue, 31 Oct 2017 21:17:16 +0100
Subject: [PATCH 09/12] Ordered the list of services in github.go

---
 github/github.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/github/github.go b/github/github.go
index 90e96bd271e..83a8430e176 100644
--- a/github/github.go
+++ b/github/github.go
@@ -139,17 +139,17 @@ type Client struct {
 	Gists          *GistsService
 	Git            *GitService
 	Gitignores     *GitignoresService
+	Licenses       *LicensesService
 	Issues         *IssuesService
+	Marketplace    *MarketplaceService
+	Migrations     *MigrationService
 	Organizations  *OrganizationsService
 	Projects       *ProjectsService
 	PullRequests   *PullRequestsService
+	Reactions      *ReactionsService
 	Repositories   *RepositoriesService
 	Search         *SearchService
 	Users          *UsersService
-	Licenses       *LicensesService
-	Marketplace    *MarketplaceService
-	Migrations     *MigrationService
-	Reactions      *ReactionsService
 }
 
 type service struct {

From f2b216a143a40b1b1da393ad1e62d4a1ae9ed6ba Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Tue, 31 Oct 2017 22:09:11 +0100
Subject: [PATCH 10/12] Renaming and ordering

---
 github/apps_marketplace.go | 6 +++---
 github/github.go           | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index d927b4a1849..3ba7e6f7000 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -160,13 +160,13 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context
 	// TODO: remove custom Accept header when this API fully launches.
 	req.Header.Set("Accept", mediaTypeMarketplacePreview)
 
-	var purchaces []*MarketplacePurchase
-	resp, err := s.client.Do(ctx, req, &purchaces)
+	var purchases []*MarketplacePurchase
+	resp, err := s.client.Do(ctx, req, &purchases)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return purchaces, resp, nil
+	return purchases, resp, nil
 }
 
 func (s *MarketplaceService) marketplaceURI(endpoint string) string {
diff --git a/github/github.go b/github/github.go
index 83a8430e176..3a0727eb69e 100644
--- a/github/github.go
+++ b/github/github.go
@@ -139,8 +139,8 @@ type Client struct {
 	Gists          *GistsService
 	Git            *GitService
 	Gitignores     *GitignoresService
-	Licenses       *LicensesService
 	Issues         *IssuesService
+	Licenses       *LicensesService
 	Marketplace    *MarketplaceService
 	Migrations     *MigrationService
 	Organizations  *OrganizationsService

From ecac90f35b294f85c86a42c83d5fc5a285838f44 Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Sun, 12 Nov 2017 21:59:48 +0100
Subject: [PATCH 11/12] Re-added the line link to  documentation

---
 github/apps_marketplace.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go
index 3ba7e6f7000..d3e689a146d 100644
--- a/github/apps_marketplace.go
+++ b/github/apps_marketplace.go
@@ -20,6 +20,8 @@ type MarketplaceService struct {
 	// 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
 }
 

From b8f7249f6486f5af294f26898ab47b2a80e35b1d Mon Sep 17 00:00:00 2001
From: Leo Ackerman <ackerman.leo@gmail.com>
Date: Sun, 12 Nov 2017 22:29:30 +0100
Subject: [PATCH 12/12] Re-generated the accessors

---
 github/github-accessors.go | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/github/github-accessors.go b/github/github-accessors.go
index 817e25cb10c..821cd83a189 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -500,6 +500,14 @@ func (c *Client) GetLicenses() *LicensesService {
 	return c.Licenses
 }
 
+// GetMarketplace returns the Marketplace field.
+func (c *Client) GetMarketplace() *MarketplaceService {
+	if c == nil {
+		return nil
+	}
+	return c.Marketplace
+}
+
 // GetMigrations returns the Migrations field.
 func (c *Client) GetMigrations() *MigrationService {
 	if c == nil {
@@ -3940,6 +3948,14 @@ func (m *MarketplacePlanAccount) GetLogin() string {
 	return *m.Login
 }
 
+// GetMarketplacePurchase returns the MarketplacePurchase field.
+func (m *MarketplacePlanAccount) GetMarketplacePurchase() *MarketplacePurchase {
+	if m == nil {
+		return nil
+	}
+	return m.MarketplacePurchase
+}
+
 // GetOrganizationBillingEmail returns the OrganizationBillingEmail field if it's non-nil, zero value otherwise.
 func (m *MarketplacePlanAccount) GetOrganizationBillingEmail() string {
 	if m == nil || m.OrganizationBillingEmail == nil {
@@ -3964,6 +3980,14 @@ func (m *MarketplacePlanAccount) GetURL() string {
 	return *m.URL
 }
 
+// GetAccount returns the Account field.
+func (m *MarketplacePurchase) GetAccount() *MarketplacePlanAccount {
+	if m == nil {
+		return nil
+	}
+	return m.Account
+}
+
 // GetBillingCycle returns the BillingCycle field if it's non-nil, zero value otherwise.
 func (m *MarketplacePurchase) GetBillingCycle() string {
 	if m == nil || m.BillingCycle == nil {
@@ -3980,6 +4004,14 @@ func (m *MarketplacePurchase) GetNextBillingDate() string {
 	return *m.NextBillingDate
 }
 
+// GetPlan returns the Plan field.
+func (m *MarketplacePurchase) GetPlan() *MarketplacePlan {
+	if m == nil {
+		return nil
+	}
+	return m.Plan
+}
+
 // GetUnitCount returns the UnitCount field if it's non-nil, zero value otherwise.
 func (m *MarketplacePurchase) GetUnitCount() int {
 	if m == nil || m.UnitCount == nil {
@@ -3988,6 +4020,14 @@ func (m *MarketplacePurchase) GetUnitCount() int {
 	return *m.UnitCount
 }
 
+// Getclient returns the client field.
+func (m *MarketplaceService) Getclient() *Client {
+	if m == nil {
+		return nil
+	}
+	return m.client
+}
+
 // GetText returns the Text field if it's non-nil, zero value otherwise.
 func (m *Match) GetText() string {
 	if m == nil || m.Text == nil {