This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
-
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.
- Loading branch information
1 parent
1cd5fe3
commit ebea9eb
Showing
6 changed files
with
106 additions
and
68 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 |
---|---|---|
@@ -1,21 +1,57 @@ | ||
package actions | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
) | ||
|
||
//ActionData defines interface to get data from actions | ||
type ActionData interface { | ||
GetWorkspace() string | ||
GetActor() string | ||
GetRepoOwner() string | ||
GetInputForAction(key string) string | ||
GetPluginName() string | ||
GetPayload() ([]byte, error) | ||
} | ||
|
||
//RealAction is the real action | ||
type RealAction struct{} | ||
|
||
//GetWorkspace returns workspace | ||
func GetWorkspace() string { | ||
func (r RealAction) GetWorkspace() string { | ||
return os.Getenv("GITHUB_WORKSPACE") | ||
} | ||
|
||
//GetActor returns the actor | ||
func GetActor() string { | ||
func (r RealAction) GetActor() string { | ||
return os.Getenv("GITHUB_ACTOR") | ||
} | ||
|
||
//GetRepoOwner returns the repo owner where action is running | ||
func GetRepoOwner() string { | ||
func (r RealAction) GetRepoOwner() string { | ||
return strings.Split(os.Getenv("GITHUB_REPOSITORY"), "/")[0] | ||
} | ||
|
||
//GetPluginName gets the plugin name | ||
func (r RealAction) GetPluginName() string { | ||
return r.GetInputForAction("plugin-name") | ||
} | ||
|
||
//GetInputForAction gets input to action | ||
func (r RealAction) GetInputForAction(key string) string { | ||
return os.Getenv(fmt.Sprintf("INPUT_%s", strings.ToUpper(key))) | ||
} | ||
|
||
//GetPayload reads payload and returns it | ||
func (r RealAction) GetPayload() ([]byte, error) { | ||
eventJSONPath := os.Getenv("GITHUB_EVENT_PATH") | ||
data, err := ioutil.ReadFile(eventJSONPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, 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 was deleted.
Oops, something went wrong.
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