Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LFS control #2429

Merged
merged 6 commits into from Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions github/repos_lfs.go
@@ -0,0 +1,49 @@
// Copyright 2022 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"
)

// EnableLFS turns the LFS (Large File Storage) feature ON for the selected repo.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/lfs#enable-git-lfs-for-a-repository
func (s *RepositoriesService) EnableLFS(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/lfs", owner, repo)

req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}

resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}

return resp, nil
}

// DisableLFS turns the LFS (Large File Storage) feature OFF for the selected repo.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/lfs#disable-git-lfs-for-a-repository
func (s *RepositoriesService) DisableLFS(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/lfs", owner, repo)

req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}

resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}

return resp, nil
}
64 changes: 64 additions & 0 deletions github/repos_lfs_test.go
@@ -0,0 +1,64 @@
// Copyright 2022 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"
"net/http"
"testing"
)

func TestRepositoriesService_EnableLFS(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/lfs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")

w.WriteHeader(http.StatusNoContent)
})

ctx := context.Background()
if _, err := client.Repositories.EnableLFS(ctx, "o", "r"); err != nil {
t.Errorf("Repositories.EnableLFS returned error: %v", err)
}

const methodName = "EnableLFS"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Repositories.EnableLFS(ctx, "\n", "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.EnableLFS(ctx, "o", "r")
})
}

func TestRepositoriesService_DisableLFS(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/lfs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")

w.WriteHeader(http.StatusNoContent)
})

ctx := context.Background()
if _, err := client.Repositories.DisableLFS(ctx, "o", "r"); err != nil {
t.Errorf("Repositories.DisableLFS returned error: %v", err)
}

const methodName = "DisableLFS"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Repositories.DisableLFS(ctx, "\n", "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.DisableLFS(ctx, "o", "r")
})
}