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

Commit

Permalink
Merge pull request #37 from kytrinyx/lint-maintainers
Browse files Browse the repository at this point in the history
Lint maintainers
  • Loading branch information
Katrina Owen authored Jul 30, 2017
2 parents bf07f1f + 7c4c2e8 commit eb648bb
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 3 deletions.
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) {
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

0 comments on commit eb648bb

Please sign in to comment.