@@ -75,7 +75,7 @@ func sanitizeTitle(s string) string {
7575 return strings .Split (s , "\n " )[0 ]
7676}
7777
78- func (v * Provider ) CreateStatus (_ context.Context , event * info.Event , statusOpts provider.StatusOpts ) error {
78+ func (v * Provider ) CreateStatus (ctx context.Context , event * info.Event , statusOpts provider.StatusOpts ) error {
7979 detailsURL := event .Provider .URL
8080 switch statusOpts .Conclusion {
8181 case "skipped" :
@@ -100,7 +100,7 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
100100 if statusOpts .DetailsURL != "" {
101101 detailsURL = statusOpts .DetailsURL
102102 }
103- if v .Client == nil {
103+ if v .ScmClient == nil {
104104 return fmt .Errorf ("no token has been set, cannot set status" )
105105 }
106106
@@ -109,16 +109,18 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
109109 key = statusOpts .Conclusion
110110 }
111111
112- _ , err := v .Client .DefaultApi .SetCommitStatus (
113- event .SHA ,
114- bbv1.BuildStatus {
115- State : statusOpts .Conclusion ,
116- Name : v .pacInfo .ApplicationName ,
117- Key : key ,
118- Description : statusOpts .Title ,
119- Url : detailsURL ,
120- },
121- )
112+ if v .pacInfo .ApplicationName != "" {
113+ key = fmt .Sprintf ("%s/%s" , v .pacInfo .ApplicationName , key )
114+ }
115+
116+ OrgAndRepo := fmt .Sprintf ("%s/%s" , event .Organization , event .Repository )
117+ opts := & scm.StatusInput {
118+ State : convertState (statusOpts .Conclusion ),
119+ Label : key ,
120+ Desc : statusOpts .Title ,
121+ Link : detailsURL ,
122+ }
123+ _ , _ , err := v .ScmClient .Repositories .CreateStatus (ctx , OrgAndRepo , event .SHA , opts )
122124 if err != nil {
123125 return err
124126 }
@@ -127,16 +129,14 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
127129 if statusOpts .OriginalPipelineRunName != "" {
128130 onPr = "/" + statusOpts .OriginalPipelineRunName
129131 }
130- bbcomment := bbv1.Comment {
131- Text : fmt .Sprintf ("**%s%s** - %s\n \n %s" , v .pacInfo .ApplicationName , onPr ,
132- statusOpts .Title , statusOpts .Text ),
133- }
132+ bbComment := fmt .Sprintf ("**%s%s** - %s\n \n %s" , v .pacInfo .ApplicationName , onPr , statusOpts .Title , statusOpts .Text )
134133
135134 if statusOpts .Conclusion == "SUCCESSFUL" && statusOpts .Status == "completed" &&
136- statusOpts .Text != "" && event .EventType == triggertype .PullRequest .String () && v .pullRequestNumber > 0 {
137- _ , err := v .Client .DefaultApi .CreatePullRequestComment (
138- v .projectKey , event .Repository , v .pullRequestNumber ,
139- bbcomment , []string {"application/json" })
135+ statusOpts .Text != "" && event .TriggerTarget == triggertype .PullRequest && event .PullRequestNumber > 0 {
136+ input := & scm.CommentInput {
137+ Body : bbComment ,
138+ }
139+ _ , _ , err := v .ScmClient .PullRequests .CreateComment (ctx , OrgAndRepo , event .PullRequestNumber , input )
140140 if err != nil {
141141 return err
142142 }
@@ -146,6 +146,19 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
146146 return nil
147147}
148148
149+ func convertState (from string ) scm.State {
150+ switch from {
151+ case "FAILED" :
152+ return scm .StateFailure
153+ case "INPROGRESS" :
154+ return scm .StatePending
155+ case "SUCCESSFUL" :
156+ return scm .StateSuccess
157+ default :
158+ return scm .StateUnknown
159+ }
160+ }
161+
149162func (v * Provider ) concatAllYamlFiles (ctx context.Context , objects []string , sha string , runevent * info.Event ) (string , error ) {
150163 var allTemplates string
151164 for _ , value := range objects {
0 commit comments