|
1 | 1 | package github
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bufio" |
4 | 5 | "context"
|
5 | 6 | "encoding/json"
|
6 | 7 | "fmt"
|
7 |
| - "io" |
8 | 8 | "net/http"
|
9 | 9 | "strconv"
|
10 | 10 | "strings"
|
@@ -754,16 +754,36 @@ func downloadLogContent(logURL string, tailLines int) (string, int, *http.Respon
|
754 | 754 | return "", 0, httpResp, fmt.Errorf("failed to download logs: HTTP %d", httpResp.StatusCode)
|
755 | 755 | }
|
756 | 756 |
|
757 |
| - content, err := io.ReadAll(httpResp.Body) |
758 |
| - if err != nil { |
759 |
| - return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err) |
| 757 | + // content, err := io.ReadAll(httpResp.Body) |
| 758 | + // if err != nil { |
| 759 | + // return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err) |
| 760 | + // } |
| 761 | + |
| 762 | + if tailLines <= 0 { |
| 763 | + tailLines = 1000 |
760 | 764 | }
|
761 | 765 |
|
762 |
| - // Clean up and format the log content for better readability |
763 |
| - logContent := strings.TrimSpace(string(content)) |
| 766 | + lines := make([]string, 0, tailLines) |
| 767 | + scanner := bufio.NewScanner(httpResp.Body) |
| 768 | + |
| 769 | + buf := make([]byte, 0, 64*1024) |
| 770 | + scanner.Buffer(buf, 1024*1024) |
| 771 | + |
| 772 | + for scanner.Scan() { |
| 773 | + line := scanner.Text() |
| 774 | + lines = append(lines, line) |
| 775 | + |
| 776 | + if len(lines) > tailLines { |
| 777 | + lines = lines[len(lines)-tailLines:] |
| 778 | + } |
| 779 | + } |
| 780 | + |
| 781 | + if err := scanner.Err(); err != nil { |
| 782 | + return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err) |
| 783 | + } |
764 | 784 |
|
765 |
| - trimmedContent, lineCount := trimContent(logContent, tailLines) |
766 |
| - return trimmedContent, lineCount, httpResp, nil |
| 785 | + content := strings.Join(lines, "\n") |
| 786 | + return content, len(lines), httpResp, nil |
767 | 787 | }
|
768 | 788 |
|
769 | 789 | // trimContent trims the content to a maximum length and returns the trimmed content and an original length
|
|
0 commit comments