Skip to content

Commit

Permalink
Merge main to config-type-support
Browse files Browse the repository at this point in the history
Signed-off-by: Zsolt Rappi <[email protected]>
  • Loading branch information
rappizs committed Sep 13, 2023
2 parents 1728445 + ee1bd0b commit e368b40
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 41 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@a09933a12a80f87b87005513f0abb1494c27a716
uses: github/codeql-action/init@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@a09933a12a80f87b87005513f0abb1494c27a716
uses: github/codeql-action/autobuild@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -77,6 +77,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@a09933a12a80f87b87005513f0abb1494c27a716
uses: github/codeql-action/analyze@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: 'Checkout Repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: 'Dependency Review'
uses: actions/dependency-review-action@f6fff72a3217f580d5afd49a46826795305b63c7
14 changes: 7 additions & 7 deletions .github/workflows/presubmits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
with:
Expand All @@ -28,13 +28,13 @@ jobs:
cache: true

- name: Build
uses: magefile/mage-action@3b833fb24c0d19eed3aa760b9eb285b4b84f420f # v2.3.0
uses: magefile/mage-action@bed74f487871c92ba8e9aa957bbf3e05bf9c9aea # v2.4.0
with:
version: v1.14.0
args: build

- name: Build images
uses: magefile/mage-action@3b833fb24c0d19eed3aa760b9eb285b4b84f420f # v2.3.0
uses: magefile/mage-action@bed74f487871c92ba8e9aa957bbf3e05bf9c9aea # v2.4.0
with:
version: v1.14.0
args: buildImagesLocal
Expand All @@ -48,7 +48,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
with:
Expand All @@ -63,7 +63,7 @@ jobs:
# run: make license-check

- name: Run verify steps
uses: magefile/mage-action@3b833fb24c0d19eed3aa760b9eb285b4b84f420f # v2.3.0
uses: magefile/mage-action@bed74f487871c92ba8e9aa957bbf3e05bf9c9aea # v2.4.0
with:
version: v1.14.0
args: verify
Expand All @@ -77,7 +77,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
with:
Expand All @@ -86,7 +86,7 @@ jobs:
cache: true

- name: Run unit tests
uses: magefile/mage-action@3b833fb24c0d19eed3aa760b9eb285b4b84f420f # v2.3.0
uses: magefile/mage-action@bed74f487871c92ba8e9aa957bbf3e05bf9c9aea # v2.4.0
with:
version: v1.14.0
args: test
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
Expand All @@ -37,7 +37,7 @@ jobs:
uses: ko-build/setup-ko@ace48d793556083a76f1e3e6068850c1f4a369aa # v0.6

- name: Install cosign
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2

- name: Log into ghcr.io
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
Expand All @@ -47,7 +47,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build images
uses: magefile/mage-action@3b833fb24c0d19eed3aa760b9eb285b4b84f420f # v2.3.0
uses: magefile/mage-action@bed74f487871c92ba8e9aa957bbf3e05bf9c9aea # v2.4.0
with:
version: v1.14.0
args: buildImages
4 changes: 2 additions & 2 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: "Checkout code"
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
persist-credentials: false

Expand Down Expand Up @@ -72,6 +72,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v2.1.27
uses: github/codeql-action/upload-sarif@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.1.27
with:
sarif_file: results.sarif
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Configuration arguments are as follows:
| repo-name | string | "uwu-tools/gh-jira-issue-sync" | true | null |
| jira-uri | string | "https://jira.example.com" | true | null |
| jira-project | string | "SYNC" | true | null |
| jira-components | []string | ["Core","Payment"] | false | null |
| since | string | "2017-07-01T13:45:00-0800" | false | "1970-01-01T00:00:00+0000" |
| timeout | duration | 500ms | false | 1m |

Expand Down Expand Up @@ -102,6 +103,11 @@ lives at a non-root URL, the path must be included. For example,
`jira-project` is the key (not the name) of the project in Jira to
which the issues will be synchronized.

`jira-components` is the names of the components in Jira
that will be added to the issues when synchronized. If a component
not found on the project or the set value is otherwise invalid,
an error will return. (optional)

`since` is the cutoff date issue-sync will use when searching for issues
to synchronize. If an issue was last updated before this time, it will
not be synchronized. Usually this is the last run of the tool. It is in
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func init() {
"set the key of the Jira project",
)

RootCmd.PersistentFlags().StringSliceVarP(
&opts.JiraComponents,
options.ConfigKeyJiraComponents,
"C",
nil,
"set the Jira components to be used",
)

RootCmd.PersistentFlags().StringVarP(
&opts.Since,
options.ConfigKeySince,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/uwu-tools/go-jira/v2 v2.0.0-20230801175343-52f822b5cb80
github.com/uwu-tools/magex v0.10.0
golang.org/x/oauth2 v0.11.0
golang.org/x/term v0.11.0
golang.org/x/term v0.12.0
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/release-sdk v0.10.3
sigs.k8s.io/release-utils v0.7.5-0.20230814131120-e16435f5a2de
Expand Down Expand Up @@ -79,7 +79,7 @@ require (
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,14 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
83 changes: 69 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ type Config struct {
// encoderRegistry is used for encoding the config file to supported Viper types.
encoderRegistry *encoding.EncoderRegistry

// components represents the Jira components the user would like use for the sync.
// Comes from the value of the `jira-components` configuration parameter.
// Items in Jira will have the components field set to these values.
components []*jira.Component

// since is the parsed value of the `since` configuration parameter, which is the earliest that
// a GitHub issue can have been updated to be retrieved.
since time.Time
Expand Down Expand Up @@ -185,6 +190,11 @@ func (c *Config) LoadJiraConfig(client *jira.Client) error {
}
c.project = proj

c.components, err = c.getComponents(proj)
if err != nil {
return err
}

c.fieldIDs, err = c.getFieldIDs(client)
if err != nil {
return err
Expand Down Expand Up @@ -281,6 +291,11 @@ func (c *Config) GetRepo() (string, string) {
return github.GetRepo(repoPath)
}

// GetJiraComponents returns the Jira component the user has configured.
func (c *Config) GetJiraComponents() []*jira.Component {
return c.components
}

// SetJiraToken adds the Jira OAuth tokens in the Viper configuration, ensuring that they
// are saved for future runs.
func (c *Config) SetJiraToken(token *oauth1.Token) {
Expand All @@ -290,20 +305,21 @@ func (c *Config) SetJiraToken(token *oauth1.Token) {

// configFile is a serializable representation of the current Viper configuration.
type configFile struct {
LogLevel string `mapstructure:"log-level,omitempty"`
GithubToken string `mapstructure:"github-token,omitempty"`
JiraUser string `mapstructure:"jira-user,omitempty"`
JiraPass string `mapstructure:"jira-pass,omitempty"`
JiraToken string `mapstructure:"jira-token,omitempty"`
JiraSecret string `mapstructure:"jira-secret,omitempty"`
JiraKey string `mapstructure:"jira-private-key-path,omitempty"`
JiraCKey string `mapstructure:"jira-consumer-key,omitempty"`
RepoName string `mapstructure:"repo-name,omitempty"`
JiraURI string `mapstructure:"jira-uri,omitempty"`
JiraProject string `mapstructure:"jira-project,omitempty"`
Since string `mapstructure:"since,omitempty"`
Confirm bool `mapstructure:"confirm,omitempty"`
Timeout time.Duration `mapstructure:"timeout,omitempty"`
LogLevel string `mapstructure:"log-level,omitempty"`
GithubToken string `mapstructure:"github-token,omitempty"`
JiraUser string `mapstructure:"jira-user,omitempty"`
JiraPass string `mapstructure:"jira-pass,omitempty"`
JiraToken string `mapstructure:"jira-token,omitempty"`
JiraSecret string `mapstructure:"jira-secret,omitempty"`
JiraKey string `mapstructure:"jira-private-key-path,omitempty"`
JiraCKey string `mapstructure:"jira-consumer-key,omitempty"`
RepoName string `mapstructure:"repo-name,omitempty"`
JiraURI string `mapstructure:"jira-uri,omitempty"`
JiraProject string `mapstructure:"jira-project,omitempty"`
Since string `mapstructure:"since,omitempty"`
JiraComponents []string `mapstructure:"jira-components"`
Confirm bool `mapstructure:"confirm,omitempty"`
Timeout time.Duration `mapstructure:"timeout,omitempty"`
}

// UpdateConfig updates the `since` parameter to now, then saves the configuration file.
Expand Down Expand Up @@ -581,6 +597,39 @@ func (c *Config) resetEncoding() error {
return nil
}

// getComponents resolves every component set in config against
// Jira project, and returns with these components used by issue-sync.
func (c *Config) getComponents(proj *jira.Project) ([]*jira.Component, error) {
var returnComponents []*jira.Component

components := c.cmdConfig.GetStringSlice(options.ConfigKeyJiraComponents)

for _, configComponent := range components {
found := false

for j := range proj.Components {
projComponent := &proj.Components[j]

if projComponent.Name == configComponent {
found = true
foundComponent := jira.Component{
Name: projComponent.Name,
ID: projComponent.ID,
}

returnComponents = append(returnComponents, &foundComponent)
}
}

if !found {
log.Errorf("The Jira project does not have such component defined: %s", configComponent)
return nil, ReadingJiraComponentError(configComponent)
}
}

return returnComponents, nil
}

// Errors

var (
Expand Down Expand Up @@ -616,3 +665,9 @@ func getConfigTypeFromName(filename string) string {

return strings.TrimPrefix(ext, ".")
}

type ReadingJiraComponentError string

func (r ReadingJiraComponentError) Error() string {
return fmt.Sprintf("could not find Jira component: %s; check that it is named correctly", string(r))
}
Loading

0 comments on commit e368b40

Please sign in to comment.