Skip to content

Commit

Permalink
feat: update Finalize function to accept multiple test files and modi…
Browse files Browse the repository at this point in the history
…fy TestFinalize accordingly
  • Loading branch information
puneeth072003 committed Dec 31, 2024
1 parent 6be8bd8 commit 55f29d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
23 changes: 15 additions & 8 deletions src/github/controllers/finalizers/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import (
"log"
)

func Finalize(installationToken string, owner string, repo string, filePath string, fileContent string) error {
type TestsResponseFormat struct {
TestName string `json:"testname"`
TestFilePath string `json:"testfilepath"`
ParentPath string `json:"parentpath"`
Code string `json:"code"`
}

func Finalize(installationToken string, owner string, repo string, testFiles []TestsResponseFormat) error {

// Get GitHub client
client, ctx := GetClient(installationToken)
Expand All @@ -27,13 +34,13 @@ func Finalize(installationToken string, owner string, repo string, filePath stri
return err
}

// Add a sample file with content
// filePath := "sample.txt"
// fileContent := "This is a sample file content."
err = CreateFiles(client, ctx, owner, repo, newBranchName, filePath, fileContent)
if err != nil {
log.Fatalf("Error creating file: %v", err)
return err
// Add the test files with content
for _, testFile := range testFiles {
err = CreateFiles(client, ctx, owner, repo, newBranchName, testFile.TestFilePath, testFile.Code)
if err != nil {
log.Fatalf("Error creating file %s: %v", testFile.TestFilePath, err)
return err
}
}

// Draft a pull request from the new branch
Expand Down
15 changes: 14 additions & 1 deletion src/github/controllers/finalizers/testfinalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ func TestFinalize(c *gin.Context) {
}

// Call Finalize with the token and other parameters
err = Finalize(token, "puneeth072003", "testing-CS", "sample.txt", "hi there")
err = Finalize(token, "puneeth072003", "testing-CS", []TestsResponseFormat{
{
TestName: "test_list_utils",
TestFilePath: "tests/test_list_utils.py",
ParentPath: "list_utils.py",
Code: "# Coughed up by CODESOURCERER",
},
{
TestName: "test_calculate_stats",
TestFilePath: "tests/test_calculate_stats.py",
ParentPath: "statistics/calculate_stats.py",
Code: "# Coughed up by CODESOURCERER",
},
})
if err != nil {
log.Printf("Error finalizing: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error finalizing"})
Expand Down
31 changes: 15 additions & 16 deletions src/github/controllers/initialwebhookhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"encoding/json"
"fmt"
"github/controllers/finalizers"
"github/controllers/initializers"
"sync"

Expand Down Expand Up @@ -226,20 +225,20 @@ func WebhookHandler(c *gin.Context) {
// Now we wait for responseData
log.Printf("Response from Server 2: %v", server2Response)

installationToken := "your_installation_token" // Replace with actual token
owner := "your_repo_owner" // Replace with actual owner
repo := "your_repo_name" // Replace with actual repo name
filePath := "path/to/your/file.txt" // Replace with actual file path
fileContent := "This is the content of the file." // Replace with actual file content

// Finalize the request
err = finalizers.Finalize(installationToken, owner, repo, filePath, fileContent)
if err != nil {
log.Printf("Error finalizing the request: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{
"message": "Error finalizing",
})
return
}
// installationToken := "your_installation_token" // Replace with actual token
// owner := "your_repo_owner" // Replace with actual owner
// repo := "your_repo_name" // Replace with actual repo name
// filePath := "path/to/your/file.txt" // Replace with actual file path
// fileContent := "This is the content of the file." // Replace with actual file content

// // Finalize the request
// err = finalizers.Finalize(installationToken, owner, repo, filePath, fileContent)
// if err != nil {
// log.Printf("Error finalizing the request: %v", err)
// c.JSON(http.StatusInternalServerError, gin.H{
// "message": "Error finalizing",
// })
// return
// }

}
2 changes: 1 addition & 1 deletion src/github/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ require (
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/yaml.v3 v3.0.1
)

0 comments on commit 55f29d7

Please sign in to comment.