Skip to content

Commit

Permalink
Merge pull request #135 from viamin/fix/134
Browse files Browse the repository at this point in the history
Remove duplicate ID and URL entries from sync notes
  • Loading branch information
viamin committed Dec 18, 2023
2 parents 812c68f + c9010fe commit a9e6b54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/pkg/
/spec/reports/
/spec/examples.txt
/temp/
/test/tmp/
/test/version_tmp/
/tmp/
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ruby.rubocop.suppressRubocopWarnings": true,
"ruby.rubocop.onSave": false
}
12 changes: 1 addition & 11 deletions lib/note_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ module NoteParser
def parsed_notes(notes:, keys: [])
return {} if notes.nil?

# TODO: remove these after we've migrated all the notes
# Strips out the old sync_id from the notes
sync_id_matcher = /(?:\bsync_id:\s.+)(\R|\z)/
match_data = sync_id_matcher.match(notes)
notes = notes.split(match_data[0]).join unless match_data.nil?
# Also remove the url
sync_url_matcher = /(?:\burl:\s.+)(\R|\z)/
match_data = sync_url_matcher.match(notes)
notes = notes.split(match_data[0]).join unless match_data.nil?

values = {}
keys.each do |key|
key_value_matcher = /(?:#{key}:\s(?<value>.+))(\R|\z)/
Expand All @@ -25,7 +15,7 @@ def parsed_notes(notes:, keys: [])
values[key] = nil
else
values[key] = match_data[:value].strip
notes = notes.split(match_data[0]).join
notes = notes.gsub(match_data[0].strip, "")
end
end
values["notes"] = notes.strip
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/note_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
expect(parsed_data["omnifocus_url"]).to be_nil
expect(parsed_data["notes"]).to eq(notes.strip)
end

context "with duplicate keys" do
let(:notes) { "#{previous_notes}\nasana_url: https://app.asana.com/0/1205790342215875/1205790342215879\n\nasana_id: 1205790342215879\nasana_url: https://app.asana.com/0/1205790342215875/1205790342215879" }

it "removes the duplicates" do
parsed_data = note_parser_class.parsed_notes(keys: %w[asana_url asana_id], notes:)
expect(parsed_data["notes"]).to eq(previous_notes.strip)
end
end
end

describe "#notes_with_values" do
Expand Down

0 comments on commit a9e6b54

Please sign in to comment.