@@ -12,20 +12,6 @@ import (
1212 "golang.org/x/oauth2"
1313)
1414
15- // Options is the struct for configurations of the githubactions plugin.
16- type Options struct {
17- Owner string
18- Repo string
19- Language * Language
20- Branch string
21- }
22-
23- // Language is the struct containing details of a programming language specified in the GitHub Actions workflow.
24- type Language struct {
25- Name string
26- Version string
27- }
28-
2915type GithubActions struct {
3016 ctx context.Context
3117 client * github.Client
@@ -53,13 +39,17 @@ func NewGithubActions(options *map[string]interface{}) (*GithubActions, error) {
5339 }, nil
5440}
5541
56- func (ga * GithubActions ) AddWorkflow (workflow Workflow ) error {
42+ func (ga * GithubActions ) GetLanguage () * Language {
43+ return ga .options .Language
44+ }
45+
46+ func (ga * GithubActions ) AddWorkflow (workflow * Workflow ) error {
5747 exists , err := ga .fileExists (workflow .workflowFileName )
5848 if err != nil {
5949 return err
6050 }
6151 if exists {
62- log .Printf ("github actions workflow %s already exists\n " , workflow .workflowFileName )
52+ log .Printf ("github actions Workflow %s already exists\n " , workflow .workflowFileName )
6353 return nil
6454 }
6555
@@ -68,10 +58,10 @@ func (ga *GithubActions) AddWorkflow(workflow Workflow) error {
6858 opts := & github.RepositoryContentFileOptions {
6959 Message : github .String (workflow .commitMessage ),
7060 Content : []byte (workflow .workflowContent ),
71- Branch : github .String ("master" ),
61+ Branch : github .String (ga . options . Branch ),
7262 }
7363
74- log .Printf ("creating github actions workflow %s...\n " , workflow .workflowFileName )
64+ log .Printf ("creating github actions Workflow %s...\n " , workflow .workflowFileName )
7565 _ , _ , err = ga .client .Repositories .CreateFile (
7666 ga .ctx ,
7767 ga .options .Owner ,
@@ -83,17 +73,17 @@ func (ga *GithubActions) AddWorkflow(workflow Workflow) error {
8373 log .Println (err )
8474 return err
8575 }
86- log .Printf ("github actions workflow %s created\n " , workflow .workflowFileName )
76+ log .Printf ("github actions Workflow %s created\n " , workflow .workflowFileName )
8777 return nil
8878}
8979
90- func (ga * GithubActions ) DeleteWorkflow (workflow Workflow ) error {
80+ func (ga * GithubActions ) DeleteWorkflow (workflow * Workflow ) error {
9181 exists , err := ga .fileExists (workflow .workflowFileName )
9282 if err != nil {
9383 return err
9484 }
9585 if ! exists {
96- log .Printf ("github actions workflow %s already removed\n " , workflow .workflowFileName )
86+ log .Printf ("github actions Workflow %s already removed\n " , workflow .workflowFileName )
9787 return nil
9888 }
9989
@@ -102,10 +92,10 @@ func (ga *GithubActions) DeleteWorkflow(workflow Workflow) error {
10292 opts := & github.RepositoryContentFileOptions {
10393 Message : github .String (workflow .commitMessage ),
10494 Content : []byte (workflow .workflowContent ),
105- Branch : github .String ("master" ),
95+ Branch : github .String (ga . options . Branch ),
10696 }
10797
108- log .Printf ("deleting github actions workflow %s...\n " , workflow .workflowFileName )
98+ log .Printf ("deleting github actions Workflow %s...\n " , workflow .workflowFileName )
10999 _ , _ , err = ga .client .Repositories .DeleteFile (
110100 ga .ctx ,
111101 ga .options .Owner ,
@@ -117,14 +107,10 @@ func (ga *GithubActions) DeleteWorkflow(workflow Workflow) error {
117107 log .Println (err )
118108 return err
119109 }
120- log .Printf ("github actions workflow %s removed\n " , workflow .workflowFileName )
110+ log .Printf ("github actions Workflow %s removed\n " , workflow .workflowFileName )
121111 return nil
122112}
123113
124- func generateGitHubWorkflowFileByName (f string ) string {
125- return fmt .Sprintf (".github/workflows/%s" , f )
126- }
127-
128114func (ga * GithubActions ) fileExists (filename string ) (bool , error ) {
129115 _ , _ , resp , err := ga .client .Repositories .GetContents (
130116 ga .ctx ,
@@ -148,6 +134,10 @@ func (ga *GithubActions) fileExists(filename string) (bool, error) {
148134 return false , fmt .Errorf ("got some error is not expected" )
149135}
150136
137+ func generateGitHubWorkflowFileByName (f string ) string {
138+ return fmt .Sprintf (".github/workflows/%s" , f )
139+ }
140+
151141func getGitHubToken () string {
152142 err := viper .BindEnv ("github_token" )
153143 if err != nil {
0 commit comments