Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CI integration tests for testing redmine issue tracker integration #126

Merged
merged 8 commits into from
Jan 7, 2021
1 change: 1 addition & 0 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ jobs:
TESTS_GITHUB_APITOKEN: ${{ secrets.TESTS_GITHUB_APITOKEN }}
TESTS_GITLAB_APITOKEN: ${{ secrets.TESTS_GITLAB_APITOKEN }}
TESTS_PIVOTALTRACKER_APITOKEN: ${{ secrets.TESTS_PIVOTALTRACKER_APITOKEN }}
TESTS_REDMINE_PRIVATE_APITOKEN: ${{ secrets.TESTS_REDMINE_PRIVATE_APITOKEN }}
run: make test
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Ignored files/folders can be specified via standard pattern-matching.
Hidden files (dotfiles, i.e. `.git`, `.gitignore`, etc) are ignored by default.

# Custom Todos
By default, `todocheck` looks for todos in the format `// TODO #231: ...` Most projects stick to this format.
By default, `todocheck` looks for todos in the format `// TODO 231: ...` Most projects stick to this format.

However, if you have some special todo format, which is different from the default one, you can specify a list of custom todo formats in your `.todocheck.yaml`
```
Expand All @@ -259,8 +259,8 @@ Note that this list adds additional formats the tool should match, but doesn't s

With the above configuration, `todocheck` will start matching todo comments in the following formats:
```
// @fix #234: a leftover task...
// ToDo #15: A funky-looking todo comment
// @fix 234: a leftover task...
// ToDo 15: A funky-looking todo comment
```


Expand Down
5 changes: 5 additions & 0 deletions issuetracker/redmine/redmine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redmine

import (
"fmt"
"strings"

"github.com/preslavmihaylov/todocheck/issuetracker"
)
Expand All @@ -23,6 +24,10 @@ func (it *IssueTracker) IssueURLFor(taskID string) string {

// TaskURLFrom taskID returns the url for the target redmine task ID to fetch
func (it *IssueTracker) taskURLFrom(taskID string) string {
if strings.HasPrefix(taskID, "#") {
taskID = taskID[1:]
}

return taskID + ".json"
}

Expand Down
85 changes: 85 additions & 0 deletions testing/integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,91 @@ func TestPivotalTrackerIntegration(t *testing.T) {
}
}

func TestPublicRedmineIntegration(t *testing.T) {
err := scenariobuilder.NewScenario().
OnlyRunOnCI().
WithBinary("../todocheck").
WithBasepath("./scenarios/integrations/redmine_public").
WithConfig("./test_configs/integrations/redmine_public.yaml").
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_public/main.go", 5).
ExpectLine("// TODO 3: A closed issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_public/main.go", 6).
ExpectLine("// TODO 4: An issue with feedback")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_public/main.go", 7).
ExpectLine("// TODO 5: A resolved issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_public/main.go", 8).
ExpectLine("// TODO 6: A rejected issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeNonExistentIssue).
WithLocation("scenarios/integrations/redmine_public/main.go", 9).
ExpectLine("// TODO 14: a non-existent issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_public/main.go", 13).
ExpectLine("// TODO #3: A closed issue")).
Run()
if err != nil {
t.Errorf("%s", err)
}
}

func TestPrivateRedmineIntegration(t *testing.T) {
err := scenariobuilder.NewScenario().
OnlyRunOnCI().
WithAuthTokenFromEnv("TESTS_REDMINE_PRIVATE_APITOKEN").
WithBinary("../todocheck").
WithBasepath("./scenarios/integrations/redmine_private").
WithConfig("./test_configs/integrations/redmine_private.yaml").
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_private/main.go", 5).
ExpectLine("// TODO 9: A closed issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_private/main.go", 6).
ExpectLine("// TODO 10: An issue with feedback")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_private/main.go", 7).
ExpectLine("// TODO 11: A resolved issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_private/main.go", 8).
ExpectLine("// TODO 12: A rejected issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeNonExistentIssue).
WithLocation("scenarios/integrations/redmine_private/main.go", 9).
ExpectLine("// TODO 14: a non-existent issue")).
ExpectTodoErr(
scenariobuilder.NewTodoErr().
WithType(errors.TODOErrTypeIssueClosed).
WithLocation("scenarios/integrations/redmine_private/main.go", 13).
ExpectLine("// TODO #9: A closed issue")).
Run()
if err != nil {
t.Errorf("%s", err)
}
}

func baseGithubScenario() *scenariobuilder.TodocheckScenario {
return scenariobuilder.NewScenario().
WithBinary("../todocheck").
Expand Down
13 changes: 13 additions & 0 deletions testing/scenarios/integrations/redmine_private/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

// TODO 7: A new issue
// TODO 8: An issue in progress
// TODO 9: A closed issue
// TODO 10: An issue with feedback
// TODO 11: A resolved issue
// TODO 12: A rejected issue
// TODO 14: a non-existent issue

// TODO #7: A new issue
// TODO #8: An issue in progress
// TODO #9: A closed issue
13 changes: 13 additions & 0 deletions testing/scenarios/integrations/redmine_public/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

// TODO 1: A new issue
// TODO 2: An issue in progress
// TODO 3: A closed issue
// TODO 4: An issue with feedback
// TODO 5: A resolved issue
// TODO 6: A rejected issue
// TODO 14: a non-existent issue

// TODO #1: A new issue
// TODO #2: An issue in progress
// TODO #3: A closed issue
4 changes: 4 additions & 0 deletions testing/test_configs/integrations/redmine_private.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
origin: https://lannisport.pmihaylov.com:3000
issue_tracker: REDMINE
auth:
type: apitoken
2 changes: 2 additions & 0 deletions testing/test_configs/integrations/redmine_public.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
origin: https://lannisport.pmihaylov.com:3000
issue_tracker: REDMINE