-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from philips-labs/feature/gh-repo-contents
Feature/gh repo contents
- Loading branch information
Showing
8 changed files
with
139 additions
and
44 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
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
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
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,17 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
) | ||
|
||
// DownloadContents downloads file contents from the given filepath | ||
func (c *Client) DownloadContents(ctx context.Context, owner, repo, filepath string) ([]byte, error) { | ||
contents, err := c.restClient.Repositories.DownloadContents(ctx, owner, repo, filepath, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer contents.Close() | ||
return ioutil.ReadAll(contents) | ||
} |
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,28 @@ | ||
package github_test | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/philips-labs/tabia/lib/github" | ||
) | ||
|
||
func TestDownloadContents(t *testing.T) { | ||
assert := assert.New(t) | ||
gh := github.NewClientWithTokenAuth(os.Getenv("TABIA_GITHUB_TOKEN")) | ||
contents, err := gh.DownloadContents(context.Background(), "philips-labs", "tabia", "README.md") | ||
if assert.NoError(err) { | ||
readme, _ := ioutil.ReadFile("../../README.md") | ||
assert.NotEmpty(contents) | ||
assert.Equal(string(readme), string(contents)) | ||
} | ||
|
||
contents, err = gh.DownloadContents(context.Background(), "philips-labs", "tabia", "IamNotThere.txt") | ||
if assert.Error(err) { | ||
assert.EqualError(err, "No file named IamNotThere.txt found in .") | ||
} | ||
} |
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
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