From 08f727830274410ec1a8547203490936240963a7 Mon Sep 17 00:00:00 2001 From: devfxx <54813298+devfxx@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:13:19 +0200 Subject: [PATCH] Add user avatar URL to the User struct and update HTML output for issue and comments --- go.mod | 7 +++++-- main.go | 30 +++++++++++++----------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 681eae1..c618e99 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,12 @@ module issue_cli go 1.23.4 +require ( + github.com/russross/blackfriday/v2 v2.1.0 + github.com/urfave/cli/v2 v2.27.5 +) + require ( github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/urfave/cli/v2 v2.27.5 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect ) diff --git a/main.go b/main.go index 5f6b6d2..fa7bf54 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,8 @@ type Issue struct { } type User struct { - Login string `json:"login"` + Login string `json:"login"` + AvatarURL string `json:"avatar_url"` } type Comment struct { @@ -76,7 +77,6 @@ func fetchIssue(c *cli.Context) error { return fmt.Errorf("invalid GitHub issue URL") } - // Extract owner, repo, and issue number from the URL parts := strings.Split(url, "/") if len(parts) < 5 { return fmt.Errorf("invalid GitHub issue URL") @@ -85,19 +85,16 @@ func fetchIssue(c *cli.Context) error { repo := parts[4] issueNumber := parts[len(parts)-1] - // Fetch the issue data from the GitHub API issue, err := getIssue(owner, repo, issueNumber) if err != nil { return err } - // Fetch the comments for the issue comments, err := getComments(owner, repo, issueNumber) if err != nil { return err } - // Convert the issue data to the specified format format := c.String("format") var output string if format == "html" { @@ -106,16 +103,13 @@ func fetchIssue(c *cli.Context) error { output = convertToMarkdown(issue, comments) } - // Check if output file path is provided outputFile := c.String("output") if outputFile != "" { - // Write the output to the specified file if err := os.WriteFile(outputFile, []byte(output), 0644); err != nil { return fmt.Errorf("failed to write to file: %v", err) } fmt.Printf("Output written to %s\n", outputFile) } else { - // Print the output to the console fmt.Println(output) } @@ -171,14 +165,11 @@ func formatDate(isoDate string) (string, error) { } func parseMarkdown(md string) string { - // Use blackfriday to convert markdown to HTML html := blackfriday.Run([]byte(md)) - // Custom handling for images re := regexp.MustCompile(`!\[Image\]\((https://github.com/user-attachments/assets/[^\)]+)\)`) html = re.ReplaceAll(html, []byte(`Image`)) - // Remove leading and trailing

tags and replace
tags with spaces re = regexp.MustCompile(`(?m)^

(.*?)

$`) html = re.ReplaceAll(html, []byte("$1")) html = bytes.ReplaceAll(html, []byte("
"), []byte(" ")) @@ -223,7 +214,6 @@ func convertToHTML(issue Issue, comments []Comment) string { createdAt, _ := formatDate(issue.CreatedAt) updatedAt, _ := formatDate(issue.UpdatedAt) - // Add CSS styling sb.WriteString(``) - // Add the toggle button and JavaScript sb.WriteString(`