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

sync: remove source or source_url if removed in prob-specs #609

Merged
merged 1 commit into from
Jun 1, 2022
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
10 changes: 6 additions & 4 deletions src/sync/sync_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ func keyOrderForFmt(e: ConceptExerciseConfig |
if e.test_runner.isSome() and not e.test_runner.get():
result.add eckTestRunner
result.add eckBlurb
if e.source.len > 0:
if e.source.isSome():
result.add eckSource
if e.source_url.len > 0:
if e.source_url.isSome():
result.add eckSourceUrl
if e.custom.isSome() and e.custom.get().len > 0:
result.add eckCustom
Expand Down Expand Up @@ -387,9 +387,11 @@ proc pretty*(e: ConceptExerciseConfig | PracticeExerciseConfig,
of eckBlurb:
result.addString("blurb", e.blurb)
of eckSource:
result.addString("source", e.source)
if e.source.isSome():
result.addString("source", e.source.get())
of eckSourceUrl:
result.addString("source_url", e.source_url)
if e.source_url.isSome():
result.addString("source_url", e.source_url.get())
of eckCustom:
addValOrNull(custom, addObject)
result.removeComma()
Expand Down
19 changes: 11 additions & 8 deletions src/sync/sync_metadata.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/[os, strformat, strutils]
import std/[options, os, strformat, strutils]
import pkg/parsetoml
import ".."/[cli, logger, types_exercise_config, types_track_config]
import "."/sync_common
Expand All @@ -9,8 +9,8 @@ import "."/sync_common
type
UpstreamMetadata = object
blurb: string
source: string
source_url: string
source: Option[string]
source_url: Option[string]

PathAndUpdatedConfig = object
path: string
Expand All @@ -23,9 +23,12 @@ proc parseMetadataToml(path: string): UpstreamMetadata =
## returns an object containing the `blurb`, `source`, and `source_url` values.
let t = parsetoml.parseFile(path)
result = UpstreamMetadata(
blurb: if t.hasKey("blurb"): t["blurb"].getStr() else: "",
source: if t.hasKey("source"): t["source"].getStr() else: "",
source_url: if t.hasKey("source_url"): t["source_url"].getStr() else: ""
blurb:
if t.hasKey("blurb"): t["blurb"].getStr() else: "",
source:
if t.hasKey("source"): t["source"].getStr().some() else: none(string),
source_url:
if t.hasKey("source_url"): t["source_url"].getStr().some() else: none(string)
)

func metadataAreUpToDate(p: PracticeExerciseConfig;
Expand All @@ -45,9 +48,9 @@ func update(p: var PracticeExerciseConfig;
p.source_url = upstreamMetadata.source_url
if upstreamMetadata.blurb.len > 0 and eckBlurb notin p.originalKeyOrder:
p.originalKeyOrder.add eckBlurb
if upstreamMetadata.source.len > 0 and eckSource notin p.originalKeyOrder:
if upstreamMetadata.source.isSome() and eckSource notin p.originalKeyOrder:
p.originalKeyOrder.add eckSource
if upstreamMetadata.source_url.len > 0 and eckSourceUrl notin p.originalKeyOrder:
if upstreamMetadata.source_url.isSome() and eckSourceUrl notin p.originalKeyOrder:
p.originalKeyOrder.add eckSourceUrl

proc addUnsynced(configPairs: var seq[PathAndUpdatedConfig];
Expand Down
8 changes: 4 additions & 4 deletions src/types_exercise_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ type
forked_from*: Option[seq[string]] ## Allowed only for a Concept Exercise.
icon*: string ## Allowed only for a Concept Exercise.
blurb*: string
source*: string
source_url*: string
source*: Option[string]
source_url*: Option[string]
custom*: Option[JsonNode]

PracticeExerciseConfig* = object
Expand All @@ -113,8 +113,8 @@ type
# The below fields are synced for a Practice Exercise that exists in the
# `exercism/problem-specifications` repo.
blurb*: string
source*: string
source_url*: string
source*: Option[string]
source_url*: Option[string]
custom*: Option[JsonNode]

{.pop.}
8 changes: 4 additions & 4 deletions tests/test_fmt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ proc testFmt =
forked_from: some(@["bar/lovely-lasagna"]),
icon: "myicon",
blurb: "Learn about the basics of Foo by following a lasagna recipe.",
source: "mysource",
source_url: "https://example.com",
source: some("mysource"),
source_url: some("https://example.com"),
custom: some(customJson)
)
const expected = """{
Expand Down Expand Up @@ -228,8 +228,8 @@ proc testFmt =
language_versions: ">=1.2.3",
test_runner: some(false),
blurb: "Write a function that returns the earned points in a single toss of a Darts game.",
source: "Inspired by an exercise created by a professor Della Paolera in Argentina",
source_url: "https://example.com",
source: some("Inspired by an exercise created by a professor Della Paolera in Argentina"),
source_url: some("https://example.com"),
custom: some(customJson)
)
const expected = """{
Expand Down
96 changes: 69 additions & 27 deletions tests/test_sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ proc testSyncCommon =
forked_from: some(@["csharp/lucians-luscious-lasagna"]),
icon: "",
blurb: "Learn about the basics of Elixir by following a lasagna recipe.",
source: "",
source_url: ""
source: none(string),
source_url: none(string)
)
let exerciseConfig = parseFile(lasagnaConfigPath, ConceptExerciseConfig)
check exerciseConfig == expected
Expand All @@ -65,8 +65,8 @@ proc testSyncCommon =
language_versions: "",
test_runner: none(bool),
blurb: "Write a function that returns the earned points in a single toss of a Darts game.",
source: "Inspired by an exercise created by a professor Della Paolera in Argentina",
source_url: ""
source: some("Inspired by an exercise created by a professor Della Paolera in Argentina"),
source_url: none(string)
)
let exerciseConfig = parseFile(dartsConfigPath, PracticeExerciseConfig)
check exerciseConfig == expected
Expand Down Expand Up @@ -158,8 +158,8 @@ proc testSyncCommon =
forked_from: some(@["bar/lovely-lasagna"]),
icon: "myicon",
blurb: "Learn about the basics of Foo by following a lasagna recipe.",
source: "mysource",
source_url: "https://example.com",
source: some("mysource"),
source_url: some("https://example.com"),
custom: some(customJson)
)
const expected = """{
Expand Down Expand Up @@ -231,8 +231,8 @@ proc testSyncCommon =
language_versions: ">=1.2.3",
test_runner: some(false),
blurb: "Write a function that returns the earned points in a single toss of a Darts game.",
source: "Inspired by an exercise created by a professor Della Paolera in Argentina",
source_url: "https://example.com",
source: some("Inspired by an exercise created by a professor Della Paolera in Argentina"),
source_url: some("https://example.com"),
custom: some(customJson)
)
const expected = """{
Expand Down Expand Up @@ -459,8 +459,8 @@ proc testSyncMetadata =
let metadataPath = joinPath(psExercisesDir, "all-your-base", "metadata.toml")
const expected = UpstreamMetadata(
blurb: "Convert a number, represented as a sequence of digits in one base, to any other base.",
source: "",
source_url: ""
source: none(string),
source_url: none(string)
)
let metadata = parseMetadataToml(metadataPath)
check metadata == expected
Expand All @@ -469,8 +469,8 @@ proc testSyncMetadata =
let metadataPath = joinPath(psExercisesDir, "darts", "metadata.toml")
const expected = UpstreamMetadata(
blurb: "Write a function that returns the earned points in a single toss of a Darts game.",
source: "Inspired by an exercise created by a professor Della Paolera in Argentina",
source_url: ""
source: some("Inspired by an exercise created by a professor Della Paolera in Argentina"),
source_url: none(string)
)
let metadata = parseMetadataToml(metadataPath)
check metadata == expected
Expand All @@ -479,8 +479,8 @@ proc testSyncMetadata =
let metadataPath = joinPath(psExercisesDir, "two-fer", "metadata.toml")
const expected = UpstreamMetadata(
blurb: """Create a sentence of the form "One for X, one for me.".""",
source: "",
source_url: "https://github.com/exercism/problem-specifications/issues/757"
source: none(string),
source_url: some("https://github.com/exercism/problem-specifications/issues/757")
)
let metadata = parseMetadataToml(metadataPath)
check metadata == expected
Expand All @@ -489,8 +489,8 @@ proc testSyncMetadata =
let metadataPath = joinPath(psExercisesDir, "collatz-conjecture", "metadata.toml")
const expected = UpstreamMetadata(
blurb: "Calculate the number of steps to reach 1 using the Collatz conjecture.",
source: "An unsolved problem in mathematics named after mathematician Lothar Collatz",
source_url: "https://en.wikipedia.org/wiki/3x_%2B_1_problem"
source: some("An unsolved problem in mathematics named after mathematician Lothar Collatz"),
source_url: some("https://en.wikipedia.org/wiki/3x_%2B_1_problem")
)
let metadata = parseMetadataToml(metadataPath)
check metadata == expected
Expand All @@ -499,8 +499,8 @@ proc testSyncMetadata =
let metadataPath = joinPath(psExercisesDir, "etl", "metadata.toml")
const expected = UpstreamMetadata(
blurb: "We are going to do the `Transform` step of an Extract-Transform-Load.",
source: "The Jumpstart Lab team",
source_url: "http://jumpstartlab.com"
source: some("The Jumpstart Lab team"),
source_url: some("http://jumpstartlab.com")
)
let metadata = parseMetadataToml(metadataPath)
check metadata == expected
Expand All @@ -511,13 +511,13 @@ proc testSyncMetadata =
suite "update and metadataAreUpToDate":
privateAccess(UpstreamMetadata)
privateAccess(PracticeExerciseConfig)
const metadata = UpstreamMetadata(
blurb: "This is a really good exercise.",
source: "From a conversation with ee7.",
source_url: "https://example.com"
)

test "updates `blurb`, `source`, and `source_url`":
const metadata = UpstreamMetadata(
blurb: "This is a really good exercise.",
source: some("From a conversation with ee7."),
source_url: some("https://example.com")
)
var p = PracticeExerciseConfig(
authors: @["foo"],
contributors: some(@["foo"]),
Expand All @@ -530,8 +530,8 @@ proc testSyncMetadata =
language_versions: "",
test_runner: none(bool),
blurb: "",
source: "",
source_url: ""
source: none(string),
source_url: none(string)
)
update(p, metadata)
let expected = PracticeExerciseConfig(
Expand All @@ -547,8 +547,50 @@ proc testSyncMetadata =
language_versions: "",
test_runner: none(bool),
blurb: "This is a really good exercise.",
source: "From a conversation with ee7.",
source_url: "https://example.com"
source: some("From a conversation with ee7."),
source_url: some("https://example.com")
)
check:
p == expected
metadataAreUpToDate(p, metadata)

test "removes `source_url` that previously existed":
const metadata = UpstreamMetadata(
blurb: "This is a really good exercise.",
source: some("From a conversation with ee7."),
source_url: none(string)
)
var p = PracticeExerciseConfig(
authors: @["foo"],
contributors: some(@["foo"]),
files: PracticeExerciseFiles(
solution: @["foo"],
test: @["foo"],
example: @["foo"],
editor: @[]
),
language_versions: "",
test_runner: none(bool),
blurb: "",
source: some("From a conversation with ee7."),
source_url: some("https://example.com")
)
update(p, metadata)
let expected = PracticeExerciseConfig(
originalKeyOrder: @[eckBlurb, eckSource],
authors: @["foo"],
contributors: some(@["foo"]),
files: PracticeExerciseFiles(
solution: @["foo"],
test: @["foo"],
example: @["foo"],
editor: @[]
),
language_versions: "",
test_runner: none(bool),
blurb: "This is a really good exercise.",
source: some("From a conversation with ee7."),
source_url: none(string)
)
check:
p == expected
Expand Down