-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DanielMabbett/relase/v0.2.0
Release/v0.2.0
- Loading branch information
Showing
632 changed files
with
271,881 additions
and
113 deletions.
There are no files selected for viewing
Empty file.
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,124 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/microsoft/azure-devops-go-api/azuredevops" | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/git" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
// rootCmd.AddCommand(versionCmd) | ||
|
||
pushAzureDevOpsCmd.Flags().StringVarP(&organisation, "organisation", "o", "", "the organisation name to target in Azure DevOps Services.") | ||
pushAzureDevOpsCmd.Flags().StringVarP(&project, "project", "p", "", "the project name to target in Azure DevOps Services.") | ||
pushAzureDevOpsCmd.Flags().StringVarP(&repo, "repo", "r", "", "the git repository name to target in Azure DevOps Services.") | ||
pushAzureDevOpsCmd.Flags().IntVarP(&pullRequestID, "pull-request-id", "i", 0, "The pull request ID in for the Git Repo in Azure DevOps Services.") | ||
pushAzureDevOpsCmd.Flags().StringVarP(&personalAccessToken, "token", "t", "", "Your PAC to Azure DevOps Services.") | ||
pushAzureDevOpsCmd.Flags().StringVarP(&planFile, "plan", "", "plan.txt", "The terraform plan file. Currently only supports .txt file outputs.") | ||
pushAzureDevOpsCmd.MarkFlagRequired("organisation") | ||
pushAzureDevOpsCmd.MarkFlagRequired("project") | ||
pushAzureDevOpsCmd.MarkFlagRequired("repo") | ||
pushAzureDevOpsCmd.MarkFlagRequired("pull-request-id") | ||
pushAzureDevOpsCmd.MarkFlagRequired("personal-access-token") | ||
pushAzureDevOpsCmd.MarkFlagRequired("plan") | ||
} | ||
|
||
var organisation string | ||
var project string | ||
var repo string | ||
var pullRequestID int | ||
var personalAccessToken string | ||
var planFile string | ||
|
||
var pushAzureDevOpsCmd = &cobra.Command{ | ||
Use: "azure-devops", | ||
Short: "Push a comment to a Pull Request to Azure DevOps services.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
// azdo alternative | ||
organizationUrl := "https://dev.azure.com/" + organisation | ||
connection := azuredevops.NewPatConnection(organizationUrl, personalAccessToken) | ||
|
||
ctx := context.Background() | ||
|
||
gitClient, err := git.NewClient(ctx, connection) | ||
if err != nil { | ||
fmt.Println("error") | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
b, err := ioutil.ReadFile(planFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
s := string(b) | ||
|
||
f, err := os.Open(planFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
|
||
line := 1 | ||
|
||
plan := "" | ||
for scanner.Scan() { | ||
if strings.Contains(scanner.Text(), "Plan:") { | ||
plan = scanner.Text() | ||
} | ||
|
||
line++ | ||
} | ||
if err := scanner.Err(); err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(plan) | ||
overview := plan | ||
overviewWrap := "`" + overview + "`" | ||
|
||
fullDetails := s | ||
fullDetailsWrap := "```\n" + fullDetails + "\n```" | ||
|
||
content := `🤖 Terrabot Response ⚡ | ||
Overview | ||
` + overviewWrap + ` | ||
<details><summary>Full Details</summary> | ||
` + fullDetailsWrap | ||
|
||
thread := git.CreateThreadArgs{ | ||
CommentThread: &git.GitPullRequestCommentThread{ | ||
Comments: &[]git.Comment{ | ||
{ | ||
Content: PtrString(content), | ||
}, | ||
}, | ||
}, | ||
PullRequestId: &pullRequestID, | ||
Project: &project, | ||
RepositoryId: &repo, | ||
} | ||
|
||
_, err = gitClient.CreateThread(ctx, thread) | ||
if err != nil { | ||
fmt.Println("Error on Creating Thread") | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
}, | ||
} | ||
|
||
func PtrString(v string) *string { return &v } |
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 |
---|---|---|
@@ -1,105 +1,10 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/microsoft/azure-devops-go-api/azuredevops" | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/git" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
// rootCmd.AddCommand(versionCmd) | ||
|
||
pushCmd.Flags().StringVarP(&organisation, "organisation", "o", "", "the organisation name to target in Azure DevOps Services.") | ||
pushCmd.Flags().StringVarP(&project, "project", "p", "", "the project name to target in Azure DevOps Services.") | ||
pushCmd.Flags().StringVarP(&repo, "repo", "r", "", "the git repository name to target in Azure DevOps Services.") | ||
pushCmd.Flags().IntVarP(&pullRequestID, "pull-request-id", "i", 0, "The pull request ID in for the Git Repo in Azure DevOps Services.") | ||
pushCmd.Flags().StringVarP(&personalAccessToken, "token", "t", "", "Your PAC to Azure DevOps Services.") | ||
pushCmd.Flags().StringVarP(&planFile, "plan", "", "plan.txt", "The terraform plan file. Currently only supports .txt file outputs.") | ||
|
||
pushCmd.MarkFlagRequired("organisation") | ||
pushCmd.MarkFlagRequired("project") | ||
pushCmd.MarkFlagRequired("repo") | ||
pushCmd.MarkFlagRequired("pull-request-id") | ||
pushCmd.MarkFlagRequired("personal-access-token") | ||
pushCmd.MarkFlagRequired("plan") | ||
} | ||
|
||
var organisation string | ||
var project string | ||
var repo string | ||
var pullRequestID int | ||
var personalAccessToken string | ||
var planFile string | ||
|
||
var pushCmd = &cobra.Command{ | ||
Use: "push", | ||
Short: "Push a comment to a Pull Request", | ||
Long: `All software has versions. This is Hugo's`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// azdo alternative | ||
organizationUrl := "https://dev.azure.com/" + organisation | ||
connection := azuredevops.NewPatConnection(organizationUrl, personalAccessToken) | ||
|
||
ctx := context.Background() | ||
|
||
gitClient, err := git.NewClient(ctx, connection) | ||
if err != nil { | ||
fmt.Println("error") | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
var text string = "Plan:" | ||
|
||
// read the whole file at once | ||
b, err := ioutil.ReadFile(planFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
s := string(b) | ||
//check whether s contains substring text | ||
fmt.Println(strings.Contains(s, text)) | ||
fmt.Println(strings.Trim(s, text)) | ||
|
||
overviewWrap := "`overview. Comming soon.`" | ||
|
||
fullDetails := s | ||
fullDetailsWrap := "```\n" + fullDetails + "\n```" | ||
|
||
content := `🤖 Terrabot Response ⚡ | ||
Overview | ||
` + overviewWrap + ` | ||
<details><summary>Full Details</summary> | ||
` + fullDetailsWrap | ||
|
||
thread := git.CreateThreadArgs{ | ||
CommentThread: &git.GitPullRequestCommentThread{ | ||
Comments: &[]git.Comment{ | ||
{ | ||
Content: PtrString(content), | ||
}, | ||
}, | ||
}, | ||
PullRequestId: &pullRequestID, | ||
Project: &project, | ||
RepositoryId: &repo, | ||
} | ||
|
||
_, err = gitClient.CreateThread(ctx, thread) | ||
if err != nil { | ||
fmt.Println("Error on Creating Thread") | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
}, | ||
Short: "Push a terraform output to a PR somewhere.", | ||
} | ||
|
||
func PtrString(v string) *string { return &v } |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.