|
1 | 1 | package github
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "bufio" |
5 | 4 | "context"
|
6 | 5 | "encoding/json"
|
7 | 6 | "fmt"
|
8 | 7 | "net/http"
|
9 | 8 | "strconv"
|
10 |
| - "strings" |
11 | 9 |
|
| 10 | + buffer "github.com/github/github-mcp-server/pkg/buffer" |
12 | 11 | ghErrors "github.com/github/github-mcp-server/pkg/errors"
|
13 | 12 | "github.com/github/github-mcp-server/pkg/translations"
|
14 | 13 | "github.com/google/go-github/v74/github"
|
@@ -758,50 +757,13 @@ func downloadLogContent(logURL string, tailLines int) (string, int, *http.Respon
|
758 | 757 | tailLines = 1000
|
759 | 758 | }
|
760 | 759 |
|
761 |
| - lines := make([]string, maxJobLogLines) |
762 |
| - validLines := make([]bool, maxJobLogLines) |
763 |
| - totalLines := 0 |
764 |
| - writeIndex := 0 |
| 760 | + processedInput, totalLines, httpResp, err := buffer.ProcessAsRingBufferToEnd(httpResp, tailLines) |
765 | 761 |
|
766 |
| - scanner := bufio.NewScanner(httpResp.Body) |
767 |
| - scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024) |
768 |
| - |
769 |
| - for scanner.Scan() { |
770 |
| - line := scanner.Text() |
771 |
| - totalLines++ |
772 |
| - |
773 |
| - lines[writeIndex] = line |
774 |
| - validLines[writeIndex] = true |
775 |
| - writeIndex = (writeIndex + 1) % maxJobLogLines |
776 |
| - } |
777 |
| - |
778 |
| - if err := scanner.Err(); err != nil { |
779 |
| - return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err) |
780 |
| - } |
781 |
| - |
782 |
| - var result []string |
783 |
| - linesInBuffer := totalLines |
784 |
| - if linesInBuffer > maxJobLogLines { |
785 |
| - linesInBuffer = maxJobLogLines |
786 |
| - } |
787 |
| - |
788 |
| - startIndex := 0 |
789 |
| - if totalLines > maxJobLogLines { |
790 |
| - startIndex = writeIndex |
791 |
| - } |
792 |
| - |
793 |
| - for i := 0; i < linesInBuffer; i++ { |
794 |
| - idx := (startIndex + i) % maxJobLogLines |
795 |
| - if validLines[idx] { |
796 |
| - result = append(result, lines[idx]) |
797 |
| - } |
798 |
| - } |
799 |
| - |
800 |
| - if len(result) > tailLines { |
801 |
| - result = result[len(result)-tailLines:] |
| 762 | + if len(processedInput) > tailLines { |
| 763 | + processedInput = processedInput[len(processedInput)-tailLines:] |
802 | 764 | }
|
803 | 765 |
|
804 |
| - finalResult := strings.Join(result, "\n") |
| 766 | + finalResult := processedInput |
805 | 767 |
|
806 | 768 | return finalResult, totalLines, httpResp, nil
|
807 | 769 | }
|
|
0 commit comments