-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
651078a
commit 84c986d
Showing
8 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- master | ||
- feat/org-id | ||
pull_request: | ||
branches: | ||
- master | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local config = require('orgmode.config') | ||
local utils = require('orgmode.utils') | ||
local state = require('orgmode.state.state') | ||
|
||
local OrgId = {} | ||
|
||
function OrgId.new() | ||
return OrgId._generate() | ||
end | ||
|
||
---@private | ||
---@return string | ||
function OrgId._generate() | ||
if config.org_id_method == 'uuid' then | ||
if vim.fn.executable(config.org_id_uuid_program) ~= 1 then | ||
utils.echo_error('org_id_uuid_program is not executable: ' .. config.org_id_uuid_program) | ||
return '' | ||
end | ||
return tostring(vim.fn.system(config.org_id_uuid_program):gsub('%s+', '')) | ||
end | ||
|
||
if config.org_id_method == 'ts' then | ||
return tostring(os.date(config.org_id_ts_format)) | ||
end | ||
|
||
if config.org_id_method == 'org' then | ||
math.randomseed(os.clock() * 100000000000) | ||
return ('%s%s'):format(vim.trim(config.org_id_prefix or ''), math.random(100000000000000)) | ||
end | ||
|
||
utils.echo_error('Invalid org_id_method: ' .. config.org_id_method) | ||
return '' | ||
end | ||
|
||
return OrgId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
* TODO Test | ||
|
||
* TODO Test1 | ||
:PROPERTIES: | ||
:ID: 1717a012-6ca3-42bd-b471-4e6855618096 | ||
:END: | ||
|
||
* TODO Test2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
describe('org id', function() | ||
local org_id = require('orgmode.org.id') | ||
it('should generate an id using uuid method', function() | ||
local uuid = org_id.new() | ||
assert.are.same(36, #uuid) | ||
assert.is.True(uuid:match('%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x') ~= nil) | ||
end) | ||
|
||
it('should generate an id using "ts" method', function() | ||
require('orgmode').setup({ | ||
org_id_method = 'ts' | ||
}) | ||
local ts_id = org_id.new() | ||
assert.is.True(ts_id:match('%d%d%d%d%d%d%d%d%d%d%d%d%d%d') ~= nil) | ||
assert.is.True(ts_id:match(os.date('%Y%m%d%H')) ~= nil) | ||
end) | ||
|
||
it('should generate an id using "ts" method and custom format', function() | ||
require('orgmode').setup({ | ||
org_id_method = 'ts', | ||
org_id_ts_format = '%Y_%m_%d_%H_%M_%S' | ||
}) | ||
local ts_id = org_id.new() | ||
assert.is.True(ts_id:match('%d%d%d%d_%d%d_%d%d_%d%d_%d%d_%d%d') ~= nil) | ||
assert.is.True(ts_id:match(os.date('%Y_%m_%d_%H')) ~= nil) | ||
end) | ||
|
||
it('should generate an id using "org" format', function() | ||
require('orgmode').setup({ | ||
org_id_method = 'org' | ||
}) | ||
|
||
local oid = org_id.new() | ||
-- Ensure it does not generate a timestamp format | ||
assert.is.Nil(oid:match(os.date('%Y%m%d%H'))) | ||
assert.is.True(oid:match('%d+') ~= nil) | ||
assert.is.True(oid:len() >= 1) | ||
end) | ||
|
||
it('should generate an id using "org" format with custom prefix', function() | ||
require('orgmode').setup({ | ||
org_id_method = 'org', | ||
org_id_prefix = 'org_tests_' | ||
}) | ||
|
||
local oid = org_id.new() | ||
-- Ensure it does not generate a timestamp format | ||
assert.is.Nil(oid:match('org_tests_'..os.date('%Y%m%d%H'))) | ||
assert.is.True(oid:match('org_tests_%d+') ~= nil) | ||
assert.is.True(oid:len() >= 11) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters