Repository: JasonEtco/todo
Pull request #41 (2017-10-06 18:37:50)

Blob link end
Tweak the blob link end detection.


Patch:
diff --git a/lib/generate-blob-link.js b/lib/generate-blob-link.js
index ee4f361..d7997ac 100644
--- a/lib/generate-blob-link.js
+++ b/lib/generate-blob-link.js
@@ -20,7 +20,7 @@ module.exports = function generateBlobLink (context, file, contents, title, sha,
   // If the proposed end of range is past the last line of the file
   // make the end the last line of the file.
   if (totalLines < end) {
-    end = totalLines
+    end = totalLines - 1
   }
 
   let range = `L${start}-L${end}`


Test patch:
diff --git a/__tests__/fixtures/files/at-end.js b/__tests__/fixtures/files/at-end.js
index f83a5bb..eb737d2 100644
--- a/__tests__/fixtures/files/at-end.js
+++ b/__tests__/fixtures/files/at-end.js
@@ -7,4 +7,5 @@
 // code
 
 // @todo Jason!
+
 // @todo End title
\ No newline at end of file
diff --git a/__tests__/fixtures/files/more.txt b/__tests__/fixtures/files/more.txt
new file mode 100644
index 0000000..b66cbe7
--- /dev/null
+++ b/__tests__/fixtures/files/more.txt
@@ -0,0 +1,3 @@
+// @TODO update helpers.ResizeImage to return error code and do something with it here
+	return nil
+}
diff --git a/__tests__/lib/generate-blob-link.js b/__tests__/lib/generate-blob-link.js
index c3f0a5d..e6fd49c 100644
--- a/__tests__/lib/generate-blob-link.js
+++ b/__tests__/lib/generate-blob-link.js
@@ -23,21 +23,22 @@ describe('generate-blob-link', () => {
   it('generates a blob link string', () => {
     const title = 'example'
     const contents = '\n\n@todo example\n\na\na\na\n\na\na'
-    const blobLink = generateBlobLink(context, 'index.js', contents, title, payloads.basic.payload.head_commit.id, config)
-    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/f7d286aa6381bbb5045288496403d9427b0746e2/index.js#L3-L5')
+    const blobLink = generateBlobLink(context, 'index.js', contents, title, 'sha', config)
+    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/sha/index.js#L3-L5')
   })
 
   it('generates the correct blob link when the file has fewer lines than start + blobLines', () => {
-    const title = 'Jason!'
-    const contents = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'files', 'at-end.js'), 'utf8')
+    const title = 'update helpers.ResizeImage to return error code and do something with it here'
+    const contents = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'files', 'more.txt'), 'utf8')
+    config.blobLines = 5
     const blobLink = generateBlobLink(context, 'index.js', contents, title, 'sha', config)
-    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/sha/index.js#L9-L10')
+    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/sha/index.js#L1-L3')
   })
 
   it('generates the correct blob link when the keyword is at the end of the file', () => {
     const title = 'End title'
     const contents = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'files', 'at-end.js'), 'utf8')
     const blobLink = generateBlobLink(context, 'index.js', contents, title, 'sha', config)
-    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/sha/index.js#L10')
+    expect(blobLink).toBe('https://github.com/JasonEtco/test/blob/sha/index.js#L11')
   })
 })