-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add git LFS - large file storage - control (#2429)
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
}) | ||
} |