-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a command to edit existing worklogs #46
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! :)
Could you also add tests for this feature?
Also, please run npm run lint
(this fixes some lint issues and shows you also errors that you have to fix manually).
|
||
static examples = [ | ||
`${appName} edit 123456 -d "new desc"`, | ||
`${appName} e 123456 -i ISSUE_KEY_OR_ALIAS`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be rather something like ${appName} e 123456 -i abc-123
as in other examples.
static examples = [ | ||
`${appName} edit 123456 -d "new desc"`, | ||
`${appName} e 123456 -i ISSUE_KEY_OR_ALIAS`, | ||
`${appName} e 123456 -t 13-15:30 ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add more examples (with remaining flags).
return execute(async () => { | ||
cli.action.start(`Updating worklog with id ${worklog_id}`) | ||
const worklog = await worklogs.updateWorklog(worklog_id, input) | ||
cli.action.stop('Done.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about printing also worklog id
here? (this value may have been changed which is not obvious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it should, it seems like I forgot to add it.
Would the message be as in the addWorklog method, to include how to delete the, possibly changed, worklog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the message be as in the addWorklog method, to include how to delete the, possibly changed, worklog?
Yes.
@@ -95,7 +98,50 @@ export default { | |||
credentials.accountId | |||
) | |||
return { worklogs, date, scheduleDetails } | |||
}, | |||
|
|||
async updateWorklog(worklogIdInput: string, input: UpdateWorklogInput) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worklogIdInput
should be the part of UpdateWorklogInput
type.
@@ -95,7 +98,50 @@ export default { | |||
credentials.accountId | |||
) | |||
return { worklogs, date, scheduleDetails } | |||
}, | |||
|
|||
async updateWorklog(worklogIdInput: string, input: UpdateWorklogInput) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, you should call await checkToken()
to check if token is properly set. See the other methods in this scope.
throw Error('Error. Worklog id should be an integer number.') | ||
} | ||
const currentWorklog = await api.getWorklog(worklogId) | ||
const referenceDate = parseWhenArg(time.now(), input.when ? input.when : currentWorklog.startDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input.when ? input.when : currentWorklog.startDate
can be replaced with
input.when ?? currentWorklog.startDate
parseResult = parseInputDate(input.durationOrInterval, referenceDate) | ||
} | ||
|
||
const issueKey = input.issueKeyOrAlias ? input.issueKeyOrAlias : currentWorklog.issue.key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, I would use ??
here.
startDate: format(referenceDate, DATE_FORMAT), | ||
startTime: parseResult ? startTime(parseResult, input.startTime, referenceDate) : currentWorklog.startTime, | ||
description: input.description ? input.description : currentWorklog.description, | ||
remainingEstimateSeconds: remainingEstimateSeconds(referenceDate, input.remainingEstimate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't use remaining estimate
from current worklog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the remaining estimate seems to be optional, which would mean not setting it results in it not being changed.
But it could be done explicitly to make it clearer, i'll see how it behaves now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the remaining estimate seems to be optional, which would mean not setting it results in it not being changed.
But technically if the issueKey
was changed, we will create a completely new worklog, so we have to move all things from the old to the new one, including optional parameters.
Correct me if I am wrong.
timeSpentSeconds: parseResult ? parseResult.seconds : currentWorklog.timeSpentSeconds, | ||
startDate: format(referenceDate, DATE_FORMAT), | ||
startTime: parseResult ? startTime(parseResult, input.startTime, referenceDate) : currentWorklog.startTime, | ||
description: input.description ? input.description : currentWorklog.description, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above (using ??
)
} | ||
const currentWorklog = await api.getWorklog(worklogId) | ||
const referenceDate = parseWhenArg(time.now(), input.when ? input.when : currentWorklog.startDate); | ||
let parseResult = undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to declare variable as undefined explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some nitpick formatting issues.
But this code needs to be covered with some acceptance tests. Scenarios that come to my mind.
- Worklog parameters can be explicitly overridden.
- Worklog parameters are not implicitly overriden.
- Missing worklog parameters can be set.
- Not deleting worklog if it failed to be updated.
- Deleting worklog if it updated succesfully.
- User is informed that worklog did update but the old one failed to be deleted.
If you wish to add unit tests for some of the code it is also cool but I don't think it is necessary.
@MiSikora Formatting issues can be fixed automatically with running |
@Vivec1990 Are you going to finish implementing this or should I close this PR? |
I am closing this due to a lack of activity. |
This should resolve #45
The workaround to changing the associated issue is to delete the existing worklog and create a new one with the given configuration.