Skip to content

Commit

Permalink
kriskbx#126: Feat: Add noteable title to record
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrs committed Jul 1, 2024
1 parent ec5ca47 commit bd6464b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ mergeRequestColumns:
recordColumns:
- user
- iid
- title
- time

# Add columns for each project member to issue and
Expand Down
36 changes: 36 additions & 0 deletions spec/models/time.title.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const moment = require('moment');
const Config = require('../../src/include/config');
const Time = require('./../../src/models/time');
const issue = require('../../src/models/issue');
const mergeRequest = require('../../src/models/mergeRequest');
const expect = require('chai').expect;

describe('time class', () => {
it('Returns title of parent Issue', () => {
const config = new Config();
const parent = new issue(config, {title: "Test title"})
const time = new Time('1h', moment(), {}, parent, config);

expect(time.title).to.be.equal("Test title");
});

it('Returns title of parent MergeRequest', () => {
const config = new Config();
const parent = new mergeRequest(config, {title: "Test title"})
const time = new Time('1h', moment(), {}, parent, config);

expect(time.title).to.be.equal("Test title");
});

it('Returns Null for missed title or parent', () => {
const config = new Config();
const parent = new mergeRequest(config, {});
let time;
time = new Time('1h', moment(), {}, parent, config);
expect(time.title).to.be.equal(null);

time = new Time('1h', moment(), {}, null, config);
expect(time.title).to.be.equal(null);
});
});

11 changes: 10 additions & 1 deletion src/models/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class time {
* construct
* @param timeString
* @param note
* @param parent
* @param {hasTimes} parent
* @param config
*/
constructor(timeString, date = null, note, parent, config) {
Expand Down Expand Up @@ -68,6 +68,15 @@ class time {
return time.toHumanReadable(this.seconds, this._hoursPerDay, this._timeFormat);
}

/**
* Title of the linked Noteable object (Issue/MergeRequest)
*
* @returns {String|null}
*/
get title() {
return this.parent && this.parent.title || null;
}

get _timeFormat() {
return this.config && this.config.get('timeFormat', 'records') ? this.config.get('timeFormat', 'records') : '';
}
Expand Down

0 comments on commit bd6464b

Please sign in to comment.