forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
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 drone#66 from jstrachan/stuff
fix: add an API for listing files in a repository
- Loading branch information
Showing
12 changed files
with
267 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
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
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,34 @@ | ||
[ | ||
{ | ||
"type": "file", | ||
"size": 625, | ||
"name": "octokit.rb", | ||
"path": "lib/octokit.rb", | ||
"sha": "fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b", | ||
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit.rb", | ||
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b", | ||
"html_url": "https://github.com/octokit/octokit.rb/blob/master/lib/octokit.rb", | ||
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/lib/octokit.rb", | ||
"_links": { | ||
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit.rb", | ||
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b", | ||
"html": "https://github.com/octokit/octokit.rb/blob/master/lib/octokit.rb" | ||
} | ||
}, | ||
{ | ||
"type": "dir", | ||
"size": 0, | ||
"name": "octokit", | ||
"path": "lib/octokit", | ||
"sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", | ||
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit", | ||
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/trees/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", | ||
"html_url": "https://github.com/octokit/octokit.rb/tree/master/lib/octokit", | ||
"download_url": null, | ||
"_links": { | ||
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit", | ||
"git": "https://api.github.com/repos/octokit/octokit.rb/git/trees/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", | ||
"html": "https://github.com/octokit/octokit.rb/tree/master/lib/octokit" | ||
} | ||
} | ||
] |
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,18 @@ | ||
[ | ||
{ | ||
"Name": "octokit.rb", | ||
"Path": "lib/octokit.rb", | ||
"Type": "file", | ||
"Size": 625, | ||
"Sha": "fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b", | ||
"Link": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit.rb" | ||
}, | ||
{ | ||
"Name": "octokit", | ||
"Path": "lib/octokit", | ||
"Type": "dir", | ||
"Size": 0, | ||
"Sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", | ||
"Link": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit" | ||
} | ||
] |
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jenkins-x/go-scm/scm" | ||
"github.com/jenkins-x/go-scm/scm/factory" | ||
"github.com/jenkins-x/go-scm/scm/factory/examples/helpers" | ||
) | ||
|
||
func main() { | ||
client, err := factory.NewClientFromEnvironment() | ||
if err != nil { | ||
helpers.Fail(err) | ||
return | ||
} | ||
|
||
ctx := context.Background() | ||
args := os.Args | ||
if len(args) < 4 { | ||
fmt.Printf("arguments: owner repository path\n") | ||
return | ||
} | ||
|
||
owner := args[1] | ||
repo := args[2] | ||
path := args[3] | ||
ref := "master" | ||
if len(args) > 4 { | ||
ref = args[4] | ||
} | ||
|
||
fullRepo := scm.Join(owner, repo) | ||
|
||
fmt.Printf("getting content for repository %s/%s and path: %s with ref: %s\n", owner, repo, path, ref) | ||
files, _, err := client.Contents.List(ctx, fullRepo, path, ref) | ||
if err != nil { | ||
helpers.Fail(err) | ||
return | ||
} | ||
fmt.Printf("found %d files\n", len(files)) | ||
|
||
for _, f := range files { | ||
fmt.Printf("\t%s size: %d type %s\n", f.Path, f.Size, f.Type) | ||
} | ||
} | ||
|
||
func createListOptions() scm.ListOptions { | ||
return scm.ListOptions{ | ||
Size: 1000, | ||
} | ||
} |
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jenkins-x/go-scm/scm" | ||
"github.com/jenkins-x/go-scm/scm/factory" | ||
"github.com/jenkins-x/go-scm/scm/factory/examples/helpers" | ||
) | ||
|
||
func main() { | ||
client, err := factory.NewClientFromEnvironment() | ||
if err != nil { | ||
helpers.Fail(err) | ||
return | ||
} | ||
|
||
ctx := context.Background() | ||
args := os.Args | ||
if len(args) < 4 { | ||
fmt.Printf("arguments: owner repository path\n") | ||
return | ||
} | ||
|
||
owner := args[1] | ||
repo := args[2] | ||
path := args[3] | ||
ref := "master" | ||
if len(args) > 4 { | ||
ref = args[4] | ||
} | ||
|
||
fullRepo := scm.Join(owner, repo) | ||
|
||
fmt.Printf("getting content for repository %s/%s and path: %s with ref: %s\n", owner, repo, path, ref) | ||
content, _, err := client.Contents.Find(ctx, fullRepo, path, ref) | ||
if err != nil { | ||
helpers.Fail(err) | ||
return | ||
} | ||
|
||
fmt.Printf("result path %s\n", content.Path) | ||
fmt.Printf("%s\n", string(content.Data)) | ||
} | ||
|
||
func createListOptions() scm.ListOptions { | ||
return scm.ListOptions{ | ||
Size: 1000, | ||
} | ||
} |