Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Lint maintainers #37

Merged
merged 2 commits into from
Jul 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/lint_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ func ExampleLint() {
// -> The implementation for 'two' is missing a test suite.
// -> An implementation for 'zero' was found, but config.json specifies that it should be foregone (not implemented).
}

func ExampleLintMaintainers() {
lintTrack("../fixtures/broken-maintainers")
// Output:
// -> invalid config ../fixtures/broken-maintainers/config/maintainers.json -- invalid character '}' looking for beginning of object key string
}
1 change: 1 addition & 0 deletions fixtures/broken-maintainers/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions fixtures/broken-maintainers/config/maintainers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"maintainers": [
{
"github_username": "alice",
"show_on_website": false,
}
],
"docs_url": "http://example.com/docs"
}
12 changes: 12 additions & 0 deletions fixtures/numbers/config/maintainers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"maintainers": [
{
"github_username": "alice",
"show_on_website": false,
"alumnus": false,
"name": "Alice Jones",
"bio": null
}
],
"docs_url": "http://example.com/docs"
}
47 changes: 47 additions & 0 deletions track/maintainer_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package track

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

// MaintainerConfig contains the list of current and previous maintainers.
// The files is used both to manage the GitHub maintainer team, as well
// as to configure the display values for each maintainer on the Exercism
// website.
type MaintainerConfig struct {
Maintainers []Maintainer `json:"maintainers"`
DocsURL string `json:"docs_url"`
}

// Maintainer contains data about a track maintainer.
type Maintainer struct {
Username string `json:"github_username"`
ShowOnWebsite bool `json:"show_on_website"`
Alumnus bool `json:"alumnus"`
Name string `json:"name"`
Bio string `json:"bio"`
LinkText string `json:"link_text"`
LinkURL string `json:"link_url"`
AvatarURL string `json:"avatar_url"`
}

// NewMaintainerConfig reads the maintainer config file, if present.
func NewMaintainerConfig(path string) (MaintainerConfig, error) {
mc := MaintainerConfig{}
if _, err := os.Stat(path); os.IsNotExist(err) {
return mc, nil
}

bytes, err := ioutil.ReadFile(path)
if err != nil {
return mc, err
}
err = json.Unmarshal(bytes, &mc)
if err != nil {
return mc, fmt.Errorf("invalid config %s -- %s", path, err.Error())
}
return mc, nil
}
26 changes: 26 additions & 0 deletions track/maintainer_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package track

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestBrokenMaintainerConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this test pattern. Short, simple, and clearly showcases how linting for the maintainers file works.

if _, err := NewMaintainerConfig("../fixtures/broken-maintainers/config/maintainers.json"); err == nil {
t.Errorf("Expected broken JSON")
}
}

func TestValidMaintainerConfig(t *testing.T) {
mc, err := NewMaintainerConfig("../fixtures/numbers/config/maintainers.json")
if err != nil {
t.Errorf("Expected valid JSON: %s", err)
}
assert.Equal(t, "alice", mc.Maintainers[0].Username)
}

func TestIgnoreMissingMaintainerConfig(t *testing.T) {
_, err := NewMaintainerConfig("../fixtures/no-such-file.json")
assert.NoError(t, err)
}
13 changes: 10 additions & 3 deletions track/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

// Track is a collection of Exercism exercises for a programming language.
type Track struct {
path string
Config Config
Exercises []Exercise
path string
Config Config
MaintainerConfig MaintainerConfig
Exercises []Exercise
}

// New loads a track.
Expand All @@ -24,6 +25,12 @@ func New(path string) (Track, error) {
}
track.Config = c

mc, err := NewMaintainerConfig(filepath.Join(path, "config", "maintainers.json"))
if err != nil {
return track, err
}
track.MaintainerConfig = mc

dir := filepath.Join(track.path, "exercises")
files, err := ioutil.ReadDir(dir)
if err != nil {
Expand Down