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 3 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 2013 The go-github AUTHORS. All rights reserved.
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
//
// 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 feature ON for selected repo.
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
//
// 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 string, repo string) (*Response, error) {
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
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 feature OFF for selected repo.
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
//
// Github API docs: https://docs.github.com/en/rest/repos/lfs#disable-git-lfs-for-a-repository
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
func (s *RepositoriesService) DisableLfs(ctx context.Context, owner string, repo string) (*Response, error) {
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
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 2013 The go-github AUTHORS. All rights reserved.
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
//
// 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"
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
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"
dsm-kb marked this conversation as resolved.
Show resolved Hide resolved
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")
})
}