Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59b5db0

Browse files
committedApr 3, 2025··
update: Set remeber-ok-to-test settings to false by default
`remeber-ok-to-test` setting is set to false by default to mitigate security risks of enabling an attacker to gain trust of repo owner and push malicious code. fixes: #1798 https://issues.redhat.com/browse/SRVKP-7238 Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 5d8a119 commit 59b5db0

File tree

15 files changed

+109
-14
lines changed

15 files changed

+109
-14
lines changed
 

‎pkg/formatting/starting.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ import (
77
)
88

99
//go:embed templates/starting.go.tmpl
10-
var StartingPipelineRunText string
10+
var StartingPipelineRunHTML string
11+
12+
//go:embed templates/starting.markdown.go.tmpl
13+
var StartingPipelineRunMarkdown string
1114

1215
//go:embed templates/queuing.go.tmpl
13-
var QueuingPipelineRunText string
16+
var QueuingPipelineRunHTML string
17+
18+
//go:embed templates/queuing.markdown.go.tmpl
19+
var QueuingPipelineRunMarkdown string
1420

1521
//go:embed templates/pipelinerunstatus.tmpl
16-
var PipelineRunStatusText string
22+
var PipelineRunStatusHTML string
23+
24+
//go:embed templates/pipelinerunstatus_markdown.tmpl
25+
var PipelineRunStatusMarkDown string
1726

1827
type MessageTemplate struct {
1928
PipelineRunName string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- **Namespace**: [{{ .Mt.Namespace }}]({{ .Mt.NamespaceURL }})
2+
- **PipelineRun**: [{{ .Mt.PipelineRunName }}]({{ .Mt.ConsoleURL }})
3+
4+
---
5+
6+
### Task Statuses:
7+
8+
| **Status** | **Name** | **Duration** |
9+
|------------|----------|--------------|
10+
{{ .Mt.TaskStatus }}
11+
12+
{{- if not (eq .Mt.FailureSnippet "")}}
13+
---
14+
15+
### Failure snippet:
16+
{{ .Mt.FailureSnippet }}
17+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PipelineRun **{{ .Mt.PipelineRunName }}** has been queued in namespace **{{ .Mt.Namespace }}**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Starting PipelineRun **{{ .Mt.PipelineRunName }}** in namespace **{{ .Mt.Namespace }}**
2+
3+
You can monitor the execution using the [{{ .Mt.ConsoleName }}]({{ .Mt.ConsoleURL }}) PipelineRun viewer or through the command line by using the [{{ .Mt.TknBinary }}]({{ .Mt.TknBinaryURL }}) CLI with the following command:
4+
5+
`{{ .Mt.TknBinary }} pr logs -n {{ .Mt.Namespace }} {{ .Mt.PipelineRunName }} -f`

‎pkg/pipelineascode/pipelineascode.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
226226
TknBinary: settings.TknBinaryName,
227227
TknBinaryURL: settings.TknBinaryURL,
228228
}
229-
msg, err := mt.MakeTemplate(formatting.StartingPipelineRunText)
229+
230+
msg, err := mt.MakeTemplate(p.vcx.GetTemplate(provider.StartingPipelineType))
230231
if err != nil {
231232
return nil, fmt.Errorf("cannot create message template: %w", err)
232233
}
@@ -243,7 +244,7 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
243244
// if pipelineRun is in pending state then report status as queued
244245
if pr.Spec.Status == tektonv1.PipelineRunSpecStatusPending {
245246
status.Status = queuedStatus
246-
if status.Text, err = mt.MakeTemplate(formatting.QueuingPipelineRunText); err != nil {
247+
if status.Text, err = mt.MakeTemplate(p.vcx.GetTemplate(provider.QueueingPipelineType)); err != nil {
247248
return nil, fmt.Errorf("cannot create message template: %w", err)
248249
}
249250
}

‎pkg/provider/bitbucketcloud/bitbucket.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Provider struct {
2929
Token, APIURL *string
3030
Username *string
3131
provenance string
32+
eventEmitter *events.EventEmitter
33+
repo *v1alpha1.Repository
3234
}
3335

3436
// CheckPolicyAllowing TODO: Implement ME.
@@ -45,9 +47,7 @@ func (v *Provider) SetPacInfo(pacInfo *info.PacOpts) {
4547
v.pacInfo = pacInfo
4648
}
4749

48-
const taskStatusTemplate = `| **Status** | **Duration** | **Name** |
49-
| --- | --- | --- |
50-
{{range $taskrun := .TaskRunList }}|{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}|{{ formatDuration $taskrun.PipelineRunTaskRunStatus.Status.StartTime $taskrun.PipelineRunTaskRunStatus.Status.CompletionTime }}|{{ $taskrun.ConsoleLogURL }}|
50+
const taskStatusTemplate = `{{range $taskrun := .TaskRunList }} | **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** | {{ $taskrun.ConsoleLogURL }} | *{{ formatDuration $taskrun.PipelineRunTaskRunStatus.Status.StartTime $taskrun.PipelineRunTaskRunStatus.Status.CompletionTime }}* |
5151
{{ end }}`
5252

5353
func (v *Provider) Validate(_ context.Context, _ *params.Run, _ *info.Event) error {
@@ -110,7 +110,10 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusopts
110110

111111
_, err := v.Client.Repositories.Commits.CreateCommitStatus(cmo, cso)
112112
if err != nil {
113-
return err
113+
// Only emit an event to notify the user that something went wrong with the commit status API,
114+
// and proceed with creating the comment (if applicable).
115+
v.eventEmitter.EmitMessage(v.repo, zap.ErrorLevel, "FailedToSetCommitStatus",
116+
"cannot set status with the Bitbucket Cloud token because of: "+err.Error())
114117
}
115118

116119
eventType := triggertype.IsPullRequestType(event.EventType)
@@ -176,7 +179,7 @@ func (v *Provider) GetFileInsideRepo(_ context.Context, event *info.Event, path,
176179
return v.getBlob(event, revision, path)
177180
}
178181

179-
func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Event, _ *v1alpha1.Repository, _ *events.EventEmitter) error {
182+
func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Event, repo *v1alpha1.Repository, eventEmitter *events.EventEmitter) error {
180183
if event.Provider.Token == "" {
181184
return fmt.Errorf("no git_provider.secret has been set in the repo crd")
182185
}
@@ -187,6 +190,8 @@ func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Eve
187190
v.Token = &event.Provider.Token
188191
v.Username = &event.Provider.User
189192
v.run = run
193+
v.eventEmitter = eventEmitter
194+
v.repo = repo
190195
return nil
191196
}
192197

@@ -297,3 +302,7 @@ func (v *Provider) GetFiles(_ context.Context, _ *info.Event) (changedfiles.Chan
297302
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
298303
return "", nil
299304
}
305+
306+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
307+
return provider.GetMarkdownTemplate(commentType)
308+
}

‎pkg/provider/bitbucketdatacenter/bitbucketdatacenter.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"go.uber.org/zap"
2424
)
2525

26-
const taskStatusTemplate = `
27-
{{range $taskrun := .TaskRunList }}* **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** {{ $taskrun.ConsoleLogURL }} *{{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }}*
26+
const taskStatusTemplate = `{{range $taskrun := .TaskRunList }}| **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** | {{ $taskrun.ConsoleLogURL }} | *{{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }}* |
2827
{{ end }}`
2928
const apiResponseLimit = 100
3029

@@ -418,3 +417,7 @@ func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedf
418417
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
419418
return "", nil
420419
}
420+
421+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
422+
return provider.GetMarkdownTemplate(commentType)
423+
}

‎pkg/provider/gitea/gitea.go

+4
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,7 @@ func (v *Provider) GetFiles(_ context.Context, runevent *info.Event) (changedfil
403403
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
404404
return "", nil
405405
}
406+
407+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
408+
return provider.GetHTMLTemplate(commentType)
409+
}

‎pkg/provider/github/github.go

+4
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,7 @@ func (v *Provider) isHeadCommitOfBranch(ctx context.Context, runevent *info.Even
603603
}
604604
return fmt.Errorf("provided SHA %s is not the HEAD commit of the branch %s", runevent.SHA, branchName)
605605
}
606+
607+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
608+
return provider.GetHTMLTemplate(commentType)
609+
}

‎pkg/provider/gitlab/gitlab.go

+4
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,7 @@ func (v *Provider) isHeadCommitOfBranch(runevent *info.Event, branchName string)
460460

461461
return fmt.Errorf("provided SHA %s is not the HEAD commit of the branch %s", runevent.SHA, branchName)
462462
}
463+
464+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
465+
return provider.GetHTMLTemplate(commentType)
466+
}

‎pkg/provider/interface.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Interface interface {
4545
GetTaskURI(ctx context.Context, event *info.Event, uri string) (bool, string, error)
4646
CreateToken(context.Context, []string, *info.Event) (string, error)
4747
CheckPolicyAllowing(context.Context, *info.Event, []string) (bool, string)
48+
GetTemplate(CommentType) string
4849
}
4950

5051
const DefaultProviderAPIUser = "git"

‎pkg/provider/provider.go

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"strings"
88

9+
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
910
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1011
"gopkg.in/yaml.v2"
1112
)
@@ -28,6 +29,38 @@ const (
2829
GitHubApp = "GitHubApp"
2930
)
3031

32+
type CommentType int
33+
34+
const (
35+
StartingPipelineType CommentType = iota
36+
PipelineRunStatusType
37+
QueueingPipelineType
38+
)
39+
40+
func GetHTMLTemplate(commentType CommentType) string {
41+
switch commentType {
42+
case StartingPipelineType:
43+
return formatting.StartingPipelineRunHTML
44+
case PipelineRunStatusType:
45+
return formatting.PipelineRunStatusHTML
46+
case QueueingPipelineType:
47+
return formatting.QueuingPipelineRunHTML
48+
}
49+
return ""
50+
}
51+
52+
func GetMarkdownTemplate(commentType CommentType) string {
53+
switch commentType {
54+
case StartingPipelineType:
55+
return formatting.StartingPipelineRunMarkdown
56+
case PipelineRunStatusType:
57+
return formatting.PipelineRunStatusMarkDown
58+
case QueueingPipelineType:
59+
return formatting.QueuingPipelineRunMarkdown
60+
}
61+
return ""
62+
}
63+
3164
func Valid(value string, validValues []string) bool {
3265
for _, v := range validValues {
3366
if v == value {

‎pkg/reconciler/reconciler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger *
276276
TknBinary: settings.TknBinaryName,
277277
TknBinaryURL: settings.TknBinaryURL,
278278
}
279-
msg, err := mt.MakeTemplate(formatting.StartingPipelineRunText)
279+
msg, err := mt.MakeTemplate(detectedProvider.GetTemplate(provider.StartingPipelineType))
280280
if err != nil {
281281
return fmt.Errorf("cannot create message template: %w", err)
282282
}

‎pkg/reconciler/status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (r *Reconciler) postFinalStatus(ctx context.Context, logger *zap.SugaredLog
138138
}
139139
}
140140
var tmplStatusText string
141-
if tmplStatusText, err = mt.MakeTemplate(formatting.PipelineRunStatusText); err != nil {
141+
if tmplStatusText, err = mt.MakeTemplate(vcx.GetTemplate(provider.PipelineRunStatusType)); err != nil {
142142
return nil, fmt.Errorf("cannot create message template: %w", err)
143143
}
144144

‎pkg/test/provider/testwebvcs.go

+4
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ func (v *TestProviderImp) GetFiles(_ context.Context, _ *info.Event) (changedfil
120120
func (v *TestProviderImp) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
121121
return "", nil
122122
}
123+
124+
func (v *TestProviderImp) GetTemplate(commentType provider.CommentType) string {
125+
return provider.GetHTMLTemplate(commentType)
126+
}

0 commit comments

Comments
 (0)
Please sign in to comment.