This repository was archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
initial imlementation of list repos (#3) #13
Open
root360-AndreasUlm
wants to merge
13
commits into
go-gitea:master
Choose a base branch
from
root360-AndreasUlm:list_repos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5bd2eee
initial imlementation of list repos (#3)
root360-AndreasUlm 2599cff
improved code style
root360-AndreasUlm b96a190
removed header & changed delimiter to pipe
root360-AndreasUlm aee0e7d
Merge branch 'master' into list_repos
lunny bf9620d
chore: go support combine all coverage file (#24)
appleboy 9128037
Add missing make-compress to fix release (#23)
lunny 9021a0e
ran 'make fmt'
root360-AndreasUlm 1aa915e
initial imlementation of list repos (#3)
root360-AndreasUlm 3797d6b
improved code style
root360-AndreasUlm 0fb281b
removed header & changed delimiter to pipe
root360-AndreasUlm 01d4f92
ran 'make fmt'
root360-AndreasUlm 5584a07
Merge branch 'list_repos' of ssh://root360_github/root360-AndreasUlm/…
root360-AndreasUlm 2d1907e
added subcommand ls & filter flags
root360-AndreasUlm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,84 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
//"code.gitea.io/sdk/gitea" | ||
root360-AndreasUlm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
// CmdRepos represents to login a gitea server. | ||
var CmdRepos = cli.Command{ | ||
Name: "repos", | ||
Usage: "Operate with repositories", | ||
Description: `Operate with repositories`, | ||
Action: runRepos, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "login, l", | ||
Usage: "Indicate one login, optional when inside a gitea repository", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "noheader", | ||
Usage: "Skip header on output.", | ||
}, | ||
}, | ||
} | ||
|
||
func runRepos(ctx *cli.Context) error { | ||
login := initCommandLoginOnly(ctx) | ||
|
||
rps, err := login.Client().ListMyRepos() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(rps) == 0 { | ||
fmt.Println("No repositories found") | ||
return nil | ||
} | ||
|
||
if noheader := getGlobalFlag(ctx, "noheader"); noheader != "true" { | ||
fmt.Printf("Name\tType/Mode\tSSH-URL\tOwner\n") | ||
} | ||
for _, rp := range rps { | ||
var mode = "source" | ||
if rp.Fork { | ||
mode = "fork" | ||
} | ||
if rp.Mirror { | ||
mode = "mirror" | ||
} | ||
fmt.Printf("%s\t%s\t%s\t%s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func initCommandLoginOnly(ctx *cli.Context) (*Login) { | ||
err := loadConfig(yamlConfigPath) | ||
if err != nil { | ||
log.Fatal("load config file failed", yamlConfigPath) | ||
} | ||
|
||
var login *Login | ||
if loginFlag := getGlobalFlag(ctx, "login"); loginFlag == "" { | ||
login, err = getActiveLogin() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} else { | ||
login = getLoginByName(loginFlag) | ||
if login == nil { | ||
log.Fatal("indicated login name", loginFlag, "does not exist") | ||
} | ||
} | ||
return login | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.