-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transform to workflow as code (#3749)
- Loading branch information
Showing
56 changed files
with
1,929 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/ovh/cds/cli" | ||
"github.com/ovh/cds/sdk" | ||
) | ||
|
||
var workflowTransformAsCodeCmd = cli.Command{ | ||
Name: "ascode", | ||
Short: "Transform an existing workflow to an as code workflow", | ||
Ctx: []cli.Arg{ | ||
{Name: _ProjectKey}, | ||
{Name: _WorkflowName}, | ||
}, | ||
} | ||
|
||
func workflowTransformAsCodeRun(v cli.Values) error { | ||
w, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName)) | ||
if err != nil { | ||
return err | ||
} | ||
if w.FromRepository != "" { | ||
fmt.Println("Workflow is already as code.") | ||
return nil | ||
} | ||
|
||
ope, err := client.WorkflowTransformAsCode(v.GetString(_ProjectKey), v.GetString(_WorkflowName)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("CDS is pushing files on your repository. A pull request will be created, please wait...\n") | ||
for { | ||
if err := client.WorkflowTransformAsCodeFollow(v.GetString(_ProjectKey), v.GetString(_WorkflowName), ope); err != nil { | ||
return err | ||
} | ||
if ope.Status > sdk.OperationStatusProcessing { | ||
break | ||
} | ||
time.Sleep(1 * time.Second) | ||
} | ||
switch ope.Status { | ||
case sdk.OperationStatusDone: | ||
fmt.Println(cli.Blue(ope.Setup.Push.PRLink)) | ||
case sdk.OperationStatusError: | ||
return fmt.Errorf("cannot perform operation: %s", ope.Error) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.