sg: print teammate details to terminal (#62031)

while looking into why certain github handles were not picked up I
    noticed this was missing and it seems pretty useful
This commit is contained in:
William Bezuidenhout 2024-04-19 12:59:36 +02:00 committed by GitHub
parent 9bf06b664c
commit 1f09814d6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View File

@ -56,6 +56,7 @@ sg teammate handbook asdine
if err != nil {
return err
}
teammate, err := resolver.ResolveByName(ctx.Context, strings.Join(args, " "))
if err != nil {
return err
@ -84,7 +85,44 @@ sg teammate handbook asdine
std.Out.Writef("Opening handbook link for %s: %s", teammate.Name, teammate.HandbookLink)
return open.URL(teammate.HandbookLink)
},
}},
},
{
Name: "details",
ArgsUsage: "<nickname>",
Usage: "print the details of a Sourcegraph",
Action: func(ctx *cli.Context) error {
args := ctx.Args().Slice()
if len(args) == 0 {
return errors.New("no nickname provided")
}
handle := strings.Join(args, "")
resolver, err := getTeamResolver(ctx.Context)
if err != nil {
return err
}
teammate, err := resolver.ResolveByGitHubHandle(ctx.Context, handle)
if err != nil {
return err
}
markdownFmt := `**Name** : %s
**Slack** : %s
**Email** : %s
**GitHub** : %s
**Location** : %s
**Role** : %s
**Description**: %s`
markdown := fmt.Sprintf(markdownFmt,
teammate.Name,
teammate.SlackName,
teammate.Email,
fmt.Sprintf("[%s](https://github.com/%s)", teammate.GitHub, teammate.GitHub),
teammate.Description,
teammate.Location,
teammate.Role)
return std.Out.WriteMarkdown(markdown)
},
},
},
}
)

View File

@ -290,6 +290,7 @@ func (o *Output) WriteMarkdown(str string, opts ...MarkdownStyleOpts) error {
// wrap output at slightly less than terminal width
glamour.WithWordWrap(o.caps.Width*4/5),
glamour.WithEmoji(),
glamour.WithPreservedNewLines(),
)
if err != nil {
return errors.Wrap(err, "renderer")