Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

Vivec1990
Copy link

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.

Copy link
Owner

@szymonkozak szymonkozak left a 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`,
Copy link
Owner

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 `
Copy link
Owner

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.')
Copy link
Owner

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)

Copy link
Author

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?

Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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);
Copy link
Owner

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;
Copy link
Owner

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)
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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,
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Owner

@szymonkozak szymonkozak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments above.

Copy link
Collaborator

@MiSikora MiSikora left a 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.

  1. Worklog parameters can be explicitly overridden.
  2. Worklog parameters are not implicitly overriden.
  3. Missing worklog parameters can be set.
  4. Not deleting worklog if it failed to be updated.
  5. Deleting worklog if it updated succesfully.
  6. 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.

src/api/api.ts Show resolved Hide resolved
src/commands/edit.ts Show resolved Hide resolved
src/commands/edit.ts Show resolved Hide resolved
src/worklogs/worklogs.ts Show resolved Hide resolved
src/worklogs/worklogs.ts Show resolved Hide resolved
@szymonkozak
Copy link
Owner

@MiSikora Formatting issues can be fixed automatically with running npm run lint.

@szymonkozak
Copy link
Owner

@Vivec1990 Are you going to finish implementing this or should I close this PR?

@szymonkozak
Copy link
Owner

I am closing this due to a lack of activity.

@szymonkozak szymonkozak closed this Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add possibility to edit a worklog
3 participants