Skip to content

Commit d36bca8

Browse files
authored
Improve syncing (#7902)
* Improve syncing * Fix test
1 parent 9861468 commit d36bca8

File tree

5 files changed

+92
-7
lines changed

5 files changed

+92
-7
lines changed

app/commands/user/github_solution_syncer/files_for_iteration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def call
1818
end
1919

2020
private
21-
delegate :user, :track, :exercise, to: :iteration
21+
delegate :user, :solution, :track, :exercise, to: :iteration
2222

2323
def files
2424
exercise_files.merge(submission_files)
@@ -27,7 +27,7 @@ def files
2727
def exercise_files
2828
return {} unless syncer.sync_exercise_files?
2929

30-
iteration.solution.git_exercise.cli_files
30+
solution.git_exercise.cli_files(solution)
3131
end
3232

3333
def submission_files

app/commands/user/github_solution_syncer/sync_everything.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def sync_everything(branch_name, token = nil)
2121
repo = LocalGitRepo.new(syncer, syncer.main_branch_name, branch_name, token:)
2222

2323
user_tracks = user.user_tracks.includes(solutions: [:track, {
24-
exercise: [:track], iterations: [{ submission: :files }, :exercise, :track]
24+
exercise: [:track], iterations: [{ submission: :files }, :solution, :exercise, :track]
2525
}])
2626

2727
num_commits = 0

app/commands/user/github_solution_syncer/sync_track.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def sync_solutions(branch_name, token = nil)
2424
repo = LocalGitRepo.new(syncer, syncer.main_branch_name, branch_name, token:)
2525

2626
solutions = user_track.solutions.
27-
includes(:track, exercise: [:track], iterations: [{ submission: :files }, :exercise, :track])
27+
includes(:track, exercise: [:track], iterations: [{ submission: :files }, :solution, :exercise, :track])
2828

2929
num_commits = 0
3030
repo.update do

app/models/git/exercise.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,17 @@ def important_files
205205
end
206206
end
207207

208-
memoize
209-
def cli_files
208+
def cli_files(solution)
210209
cli_filepaths.each.with_object({}) do |filepath, hash|
211-
hash[filepath] = read_file_blob(filepath)
210+
if filepath == Git::Exercise::SPECIAL_FILEPATHS[:readme]
211+
hash[filepath] = Solution::GenerateReadmeFile.(solution)
212+
elsif filepath == Git::Exercise::SPECIAL_FILEPATHS[:help]
213+
hash[filepath] = Solution::GenerateHelpFile.(solution)
214+
elsif filepath == Git::Exercise::SPECIAL_FILEPATHS[:hints]
215+
hash[filepath] = Solution::GenerateHintsFile.(solution)
216+
else
217+
hash[filepath] = read_file_blob(filepath)
218+
end
212219
end
213220
end
214221

test/commands/user/github_solution_syncer/files_for_iteration_test.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,90 @@ class FilesForIterationTest < ActiveSupport::TestCase
5252
)
5353

5454
expected = [
55+
{ path: "solutions/ruby/bob/3/README.md", mode: "100644", type: "blob", content: readme },
56+
{ path: "solutions/ruby/bob/3/HELP.md", mode: "100644", type: "blob", content: help },
57+
{ path: "solutions/ruby/bob/3/HINTS.md", mode: "100644", type: "blob", content: hints },
5558
{ path: "solutions/ruby/bob/3/bob.rb", mode: "100644", type: "blob", content: "puts 'hi'" },
5659
{ path: "solutions/ruby/bob/3/bob_test.rb", mode: "100644", type: "blob", content: "test content\n" },
5760
{ path: "solutions/ruby/bob/3/subdir/more_bob.rb", mode: "100644", type: "blob", content: "Some subdir content\n" }
5861
]
5962
actual = FilesForIteration.(syncer, iteration)
6063
assert_equal expected, actual
6164
end
65+
66+
# rubocop:disable Naming/HeredocDelimiterNaming
67+
def readme = <<~EOS.strip
68+
# Bob
69+
70+
Welcome to Bob on Exercism's Ruby Track.
71+
If you need help running the tests or submitting your code, check out `HELP.md`.
72+
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
73+
74+
## Introduction
75+
76+
Introduction for bob
77+
78+
Extra introduction for bob
79+
80+
## Instructions
81+
82+
Instructions for bob
83+
84+
Extra instructions for bob
85+
86+
## Source
87+
88+
### Created by
89+
90+
- @erikschierboom
91+
92+
### Contributed to by
93+
94+
- @ihid
95+
96+
### Based on
97+
98+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06
99+
EOS
100+
101+
def help = <<~EOS.strip
102+
# Help
103+
104+
## Running the tests
105+
106+
Run the tests using `ruby test`.
107+
108+
## Submitting your solution
109+
110+
You can submit your solution using the `exercism submit bob.rb` command.
111+
This command will upload your solution to the Exercism website and print the solution page's URL.
112+
113+
It's possible to submit an incomplete solution which allows you to:
114+
115+
- See how others have completed the exercise
116+
- Request help from a mentor
117+
118+
## Need to get help?
119+
120+
If you'd like help solving the exercise, check the following pages:
121+
122+
- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby)
123+
- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby)
124+
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
125+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
126+
127+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
128+
129+
Stuck? Try the Ruby gitter channel.
130+
EOS
131+
132+
def hints = <<~EOS.strip
133+
# Hints
134+
135+
## General
136+
137+
- There are many useful string methods built-in
138+
EOS
62139
end
140+
# rubocop:enable Naming/HeredocDelimiterNaming
63141
end

0 commit comments

Comments
 (0)