Skip to content

Commit 65c232c

Browse files
scubbosorenisanerd
authored andcommitted
Parse permissions (#133)
Resurrecting [this PR](https://gitea.com/gitea/act/pulls/73) as the original author has [lost motivation](go-gitea/gitea#25664 (comment)) (though, to be clear - all credit belongs to them, all mistakes are mine and mine alone!) Co-authored-by: Søren L. Hansen <[email protected]> Reviewed-on: https://gitea.com/gitea/act/pulls/133 Reviewed-by: Lunny Xiao <[email protected]> Co-authored-by: Jack Jackson <[email protected]> Co-committed-by: Jack Jackson <[email protected]>
1 parent 5da4954 commit 65c232c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

pkg/jobparser/jobparser.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
6060
}
6161
job.RawRunsOn = encodeRunsOn(runsOn)
6262
swf := &SingleWorkflow{
63-
Name: workflow.Name,
64-
RawOn: workflow.RawOn,
65-
Env: workflow.Env,
66-
Defaults: workflow.Defaults,
63+
Name: workflow.Name,
64+
RawOn: workflow.RawOn,
65+
Env: workflow.Env,
66+
Defaults: workflow.Defaults,
67+
RawPermissions: workflow.RawPermissions,
6768
}
6869
if err := swf.SetJob(id, job); err != nil {
6970
return nil, fmt.Errorf("SetJob: %w", err)

pkg/jobparser/model.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010

1111
// SingleWorkflow is a workflow with single job and single matrix
1212
type SingleWorkflow struct {
13-
Name string `yaml:"name,omitempty"`
14-
RawOn yaml.Node `yaml:"on,omitempty"`
15-
Env map[string]string `yaml:"env,omitempty"`
16-
RawJobs yaml.Node `yaml:"jobs,omitempty"`
17-
Defaults Defaults `yaml:"defaults,omitempty"`
13+
Name string `yaml:"name,omitempty"`
14+
RawOn yaml.Node `yaml:"on,omitempty"`
15+
Env map[string]string `yaml:"env,omitempty"`
16+
RawJobs yaml.Node `yaml:"jobs,omitempty"`
17+
Defaults Defaults `yaml:"defaults,omitempty"`
18+
RawPermissions yaml.Node `yaml:"permissions,omitempty"`
1819
}
1920

2021
func (w *SingleWorkflow) Job() (string, *Job) {
@@ -84,6 +85,7 @@ type Job struct {
8485
With map[string]interface{} `yaml:"with,omitempty"`
8586
RawSecrets yaml.Node `yaml:"secrets,omitempty"`
8687
RawConcurrency *model.RawConcurrency `yaml:"concurrency,omitempty"`
88+
RawPermissions yaml.Node `yaml:"permissions,omitempty"`
8789
}
8890

8991
func (j *Job) Clone() *Job {
@@ -107,6 +109,7 @@ func (j *Job) Clone() *Job {
107109
With: j.With,
108110
RawSecrets: j.RawSecrets,
109111
RawConcurrency: j.RawConcurrency,
112+
RawPermissions: j.RawPermissions,
110113
}
111114
}
112115

pkg/model/workflow.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import (
1717

1818
// Workflow is the structure of the files in .github/workflows
1919
type Workflow struct {
20-
File string
21-
Name string `yaml:"name"`
22-
RawOn yaml.Node `yaml:"on"`
23-
Env map[string]string `yaml:"env"`
24-
Jobs map[string]*Job `yaml:"jobs"`
25-
Defaults Defaults `yaml:"defaults"`
26-
27-
RawConcurrency *RawConcurrency `yaml:"concurrency"` // For Gitea
20+
File string
21+
Name string `yaml:"name"`
22+
RawOn yaml.Node `yaml:"on"`
23+
Env map[string]string `yaml:"env"`
24+
Jobs map[string]*Job `yaml:"jobs"`
25+
Defaults Defaults `yaml:"defaults"`
26+
RawConcurrency *RawConcurrency `yaml:"concurrency"`
27+
RawPermissions yaml.Node `yaml:"permissions"`
2828
}
2929

3030
// On events for the workflow
@@ -201,6 +201,7 @@ type Job struct {
201201
Uses string `yaml:"uses"`
202202
With map[string]interface{} `yaml:"with"`
203203
RawSecrets yaml.Node `yaml:"secrets"`
204+
RawPermissions yaml.Node `yaml:"permissions"`
204205
Result string
205206
}
206207

0 commit comments

Comments
 (0)