diff --git a/cloud-build-go b/cloud-build-go index d30c1287f0d1d1b5ff6d6122af2c0f2b25ef34ba..2ba72c23d076c5d4d736d0a659b7bb58679905dd 100755 Binary files a/cloud-build-go and b/cloud-build-go differ diff --git a/cloudbuild/connection.go b/cloudbuild/connection.go index ba9f58407678689129644d705a4f1ef817569fbf..2021a72fc9e4d2cda0191fdfb915b38796fdd858 100644 --- a/cloudbuild/connection.go +++ b/cloudbuild/connection.go @@ -93,7 +93,7 @@ func (c *Client) CreateConnection(projectID, location, name, connType string) er } // CreateGitLabConnection creates a new GitLab connection in Cloud Build using v2 API -func (c *Client) CreateGitLabConnection(projectID, location, name string, connConfig *config.GitlabConnectionConfig, annotations map[string]string) error { +func (c *Client) CreateGitLabConnection(projectID, location, name string, connConfig *config.GitlabConnectionConfig, annotations map[string]string) (error, string) { // Format the parent string as required by the API parent := fmt.Sprintf("projects/%s/locations/%s", projectID, location) @@ -133,19 +133,17 @@ func (c *Client) CreateGitLabConnection(projectID, location, name string, connCo ).ConnectionId(name).Do() if err != nil { - return fmt.Errorf("error creating GitLab connection: %w", err) + return fmt.Errorf("error creating GitLab connection: %w", err), "" } - // Successfully created the connection + // Successfully initiated the connection creation request // Note: Due to eventual consistency in Google Cloud APIs, the connection // might not be immediately available after creation. We'll skip the validation // step as it's not necessary to confirm success, and we've already received // a successful response from the API. - fmt.Printf("Successfully created GitLab connection: %s\n", - fmt.Sprintf("projects/%s/locations/%s/connections/%s", projectID, location, name)) - - return nil + // Return the full resource name of the connection + return nil, fmt.Sprintf("projects/%s/locations/%s/connections/%s", projectID, location, name) } // GetConnection retrieves an existing connection from Cloud Build using v2 API diff --git a/cloudbuild/repository.go b/cloudbuild/repository.go index 868d36dc30a8b7c0b74f4f7e8cda29c23e6776a0..d59d9af508e8c164688749f6430420bca8bdddda 100644 --- a/cloudbuild/repository.go +++ b/cloudbuild/repository.go @@ -12,37 +12,21 @@ import ( func (c *Client) LinkRepository(projectID, location, connectionName, repoName, remoteURI string) error { // Format the connection name as required by the API (this is the parent for repository creation) connectionRef := fmt.Sprintf("projects/%s/locations/%s/connections/%s", projectID, location, connectionName) - + // Create a repository object with the required remoteUri field repository := &cloudbuild.Repository{ RemoteUri: remoteURI, // The API requires the remote URI to be specified } - + // Make the API call to create/link the repository _, err := c.service.Projects.Locations.Connections.Repositories.Create( - connectionRef, // The parent (connection) - repository, // Repository object with required fields + connectionRef, // The parent (connection) + repository, // Repository object with required fields ).RepositoryId(repoName).Do() // Set the repository ID - + if err != nil { return fmt.Errorf("error linking repository: %w", err) } - - return nil -} -// GetRepository retrieves information about a specific repository -func (c *Client) GetRepository(projectID, location, connectionName, repoName string) (*cloudbuild.Repository, error) { - // Format the repository name as required by the API - repoFullName := fmt.Sprintf("projects/%s/locations/%s/connections/%s/repositories/%s", - projectID, location, connectionName, repoName) - - // Make the API call to get the repository - repo, err := c.service.Projects.Locations.Connections.Repositories.Get(repoFullName).Do() - - if err != nil { - return nil, fmt.Errorf("error getting repository: %w", err) - } - - return repo, nil + return nil } diff --git a/main b/main index d631209c8e2f313551939a865b25d83337b0e856..1e231dbe52fffb9e34df919df0c9fcc664b50ff5 100755 Binary files a/main and b/main differ diff --git a/main.go b/main.go index 6245a915a94f053d7af85a6715117ca34b020113..ad48610fd0ccb863cfc773db8499ac025ebab503 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,27 @@ import ( "fmt" "log" "os" + "strings" "github.com/niveus/cloud-build-go/cloudbuild" "github.com/niveus/cloud-build-go/config" + cloudbuildv2 "google.golang.org/api/cloudbuild/v2" ) +// printRepositoryInfo prints debug information about a repository +func printRepositoryInfo(repo *cloudbuildv2.Repository) { + fmt.Println("Repository Information:") + fmt.Printf(" Name: %s\n", repo.Name) + fmt.Printf(" Remote URI: %s\n", repo.RemoteUri) + fmt.Printf(" Create Time: %s\n", repo.CreateTime) + fmt.Printf(" Update Time: %s\n", repo.UpdateTime) + + fmt.Println(" Annotations:") + for k, v := range repo.Annotations { + fmt.Printf(" %s: %s\n", k, v) + } +} + func main() { // Define command-line flags configPath := flag.String("config", "config/config.json", "Path to config file") @@ -88,7 +104,7 @@ func main() { connConfig.Name, projectIDValue, locationValue) // Create the GitLab connection using the Cloud Build SDK - err = client.CreateGitLabConnection( + err, resourceName := client.CreateGitLabConnection( projectIDValue, locationValue, connConfig.Name, @@ -99,8 +115,8 @@ func main() { log.Fatalf("Failed to create GitLab connection: %v", err) } - fmt.Printf("Successfully created GitLab connection: %s\n", - fmt.Sprintf("projects/%s/locations/%s/connections/%s", projectIDValue, locationValue, connConfig.Name)) + fmt.Printf("Connection creation initiated successfully. GitLab connection resource: %s\n", resourceName) + fmt.Println("Note: The connection might take a moment to become fully active in the Cloud Build system.") case "list-connections": // Use project ID and location from config