@@ -631,32 +631,65 @@ func TestAction_Context(t *testing.T) {
631631 {
632632 name : "no_payload" ,
633633 env : map [string ]string {
634- "GITHUB_EVENT_NAME" : "event_name" ,
635- "GITHUB_SHA" : "abcd1234" ,
636- "GITHUB_REF" : "main" ,
637- "GITHUB_WORKFLOW" : "test" ,
638- "GITHUB_ACTION" : "foo/bar@v0" ,
639- "GITHUB_ACTOR" : "sethvargo" ,
640- "GITHUB_JOB" : "12" ,
641- "GITHUB_RUN_NUMBER" : "34" ,
642- "GITHUB_RUN_ID" : "56" ,
643- "GITHUB_API_URL" : "https://foo.com" ,
644- "GITHUB_SERVER_URL" : "https://bar.com" ,
645- "GITHUB_GRAPHQL_URL" : "https://baz.com" ,
634+ "GITHUB_ACTION" : "__repo-owner_name-of-action-repo" ,
635+ "GITHUB_ACTION_PATH" : "/path/to/action" ,
636+ "GITHUB_ACTION_REPOSITORY" : "repo-owner/name-of-action-repo" ,
637+ "GITHUB_ACTIONS" : "true" ,
638+ "GITHUB_ACTOR" : "sethvargo" ,
639+ "GITHUB_API_URL" : "https://foo.com" ,
640+ "GITHUB_BASE_REF" : "main" ,
641+ "GITHUB_ENV" : "/path/to/env" ,
642+ "GITHUB_EVENT_NAME" : "event_name" ,
643+ "GITHUB_HEAD_REF" : "headbranch" ,
644+ "GITHUB_GRAPHQL_URL" : "https://baz.com" ,
645+ "GITHUB_JOB" : "12" ,
646+ "GITHUB_PATH" : "/path/to/path" ,
647+ "GITHUB_REF" : "refs/tags/v1.0" ,
648+ "GITHUB_REF_NAME" : "v1.0" ,
649+ "GITHUB_REF_PROTECTED" : "true" ,
650+ "GITHUB_REF_TYPE" : "tag" ,
651+ "GITHUB_REPOSITORY" : "sethvargo/baz" ,
652+ "GITHUB_REPOSITORY_OWNER" : "sethvargo" ,
653+ "GITHUB_RETENTION_DAYS" : "90" ,
654+ "GITHUB_RUN_ATTEMPT" : "6" ,
655+ "GITHUB_RUN_ID" : "56" ,
656+ "GITHUB_RUN_NUMBER" : "34" ,
657+ "GITHUB_SERVER_URL" : "https://bar.com" ,
658+ "GITHUB_SHA" : "abcd1234" ,
659+ "GITHUB_STEP_SUMMARY" : "/path/to/summary" ,
660+ "GITHUB_WORKFLOW" : "test" ,
661+ "GITHUB_WORKSPACE" : "/path/to/workspace" ,
646662 },
647663 exp : & GitHubContext {
648- EventName : "event_name" ,
649- SHA : "abcd1234" ,
650- Ref : "main" ,
651- Workflow : "test" ,
652- Action : "foo/bar@v0" ,
653- Actor : "sethvargo" ,
654- Job : "12" ,
655- RunNumber : 34 ,
656- RunID : 56 ,
657- APIURL : "https://foo.com" ,
658- ServerURL : "https://bar.com" ,
659- GraphqlURL : "https://baz.com" ,
664+ Action : "__repo-owner_name-of-action-repo" ,
665+ ActionPath : "/path/to/action" ,
666+ ActionRepository : "repo-owner/name-of-action-repo" ,
667+ Actions : true ,
668+ Actor : "sethvargo" ,
669+ APIURL : "https://foo.com" ,
670+ BaseRef : "main" ,
671+ Env : "/path/to/env" ,
672+ EventName : "event_name" ,
673+ // NOTE: No EventPath
674+ GraphqlURL : "https://baz.com" ,
675+ Job : "12" ,
676+ HeadRef : "headbranch" ,
677+ Path : "/path/to/path" ,
678+ Ref : "refs/tags/v1.0" ,
679+ RefName : "v1.0" ,
680+ RefProtected : true ,
681+ RefType : "tag" ,
682+ Repository : "sethvargo/baz" ,
683+ RepositoryOwner : "sethvargo" ,
684+ RetentionDays : 90 ,
685+ RunAttempt : 6 ,
686+ RunID : 56 ,
687+ RunNumber : 34 ,
688+ ServerURL : "https://bar.com" ,
689+ SHA : "abcd1234" ,
690+ StepSummary : "/path/to/summary" ,
691+ Workflow : "test" ,
692+ Workspace : "/path/to/workspace" ,
660693 },
661694 },
662695 {
@@ -700,6 +733,81 @@ func TestAction_Context(t *testing.T) {
700733 }
701734}
702735
736+ func TestGitHubContext_Repo (t * testing.T ) {
737+ t .Parallel ()
738+
739+ cases := []struct {
740+ name string
741+ context * GitHubContext
742+ expOwner string
743+ expRepo string
744+ }{
745+ {
746+ name : "empty" ,
747+ context : & GitHubContext {},
748+ expOwner : "" ,
749+ expRepo : "" ,
750+ },
751+ {
752+ name : "GITHUB_REPOSITORY env" ,
753+ context : & GitHubContext {
754+ Repository : "sethvargo/foo" ,
755+ },
756+ expOwner : "sethvargo" ,
757+ expRepo : "foo" ,
758+ },
759+ {
760+ name : "event" ,
761+ context : & GitHubContext {
762+ Event : map [string ]any {
763+ "repository" : map [string ]any {
764+ "name" : "foo" ,
765+ "owner" : map [string ]any {
766+ "name" : "sethvargo" ,
767+ },
768+ },
769+ },
770+ },
771+ expOwner : "sethvargo" ,
772+ expRepo : "foo" ,
773+ },
774+ {
775+ name : "event invalid type" ,
776+ context : & GitHubContext {
777+ Event : map [string ]any {
778+ "repository" : "sethvargo/foo" ,
779+ },
780+ },
781+ expOwner : "" ,
782+ expRepo : "" ,
783+ },
784+ {
785+ name : "owner fallback" ,
786+ context : & GitHubContext {
787+ RepositoryOwner : "sethvargo" ,
788+ },
789+ expOwner : "sethvargo" ,
790+ expRepo : "" ,
791+ },
792+ }
793+
794+ for _ , tc := range cases {
795+ tc := tc
796+
797+ t .Run (tc .name , func (t * testing.T ) {
798+ t .Parallel ()
799+
800+ owner , repo := tc .context .Repo ()
801+ if want , got := tc .expOwner , owner ; want != got {
802+ t .Errorf ("unexpected owner, want: %q, got: %q" , want , got )
803+ }
804+ if want , got := tc .expRepo , repo ; want != got {
805+ t .Errorf ("unexpected repository, want: %q, got: %q" , want , got )
806+ }
807+ })
808+ }
809+ }
810+
703811// newFakeGetenvFunc returns a new GetenvFunc that is expected to be called with
704812// the provided key. It returns the provided value if the call matches the
705813// provided key. It reports an error on test t otherwise.
0 commit comments