Giter Site home page Giter Site logo

axalian / toggl-jira Goto Github PK

View Code? Open in Web Editor NEW
2.0 5.0 4.0 2.95 MB

A sync tool to log time logged in Toggl to Jira issues

License: BSD 3-Clause "New" or "Revised" License

PHP 98.57% Smarty 0.75% Dockerfile 0.41% Shell 0.27%
toggl jira toggl-api jira-issue-tracker zf3 jira-issue sync

toggl-jira's Introduction

TogglJira

Scrutinizer Code Quality Build Status

A sync tool to log time logged in Toggl to Jira issues. It works awesomely with the Toggl Chrome plugin.

Usage

TogglJira expects Toggl entries to start with the JIRA issue ID, for example:

SUP-11 Support the Customer Service department

It will then add a WorkLog entry to issue SUP-11.

Copy config.json.dist to config.json. Fill in your details. Leave jiraLoginUsername as an empty string if your login username and username are the same, which might not be the case with JIRA Cloud and Atlassian ID. The fillIssueID and fillIssueComment keys can also be left blank if not needed. The notifyUsers key controls whether JIRA will send an email to people watching the issue when adding or updating time entries.

Then run:

php bin/toggljira.php help

or to start syncing:

php bin/toggljira.php sync [--startDate=] [--endDate=] [--overwrite=] 
  • By default the startDate is the last sync date from config.json or today.
  • By default the endDate is now.
  • By default worklogs will be combined (merged) and not overwritten.

Custom start and end date

This will sync all worklogs starting from today.

php bin/toggljira.php sync --startDate=today

This will sync all worklogs starting from 1 january 2018.

php bin/toggljira.php sync --startDate=2018-01-01

This will sync all worklogs starting from 1 january 2018 to 1 february 2018.

php bin/toggljira.php sync --startDate=2018-01-01 --endDate=2018-02-01

Overwriting existing worklogs instead of combining (merging)

This will sync all worklogs starting from 1 january 2018 to 1 february 2018 and it will overwrite existing worklogs.

php bin/toggljira.php sync --startDate=2018-01-01 --endDate=2018-02-01 --overwrite=true

That's it, enjoy!

Bonus: Running with Docker

A docker-compose.yml file is included in the repository. If you are familiar with Docker Compose, you can use this to run the script without having to configure PHP locally.

The code gets mounted to /usr/src/toggl-jira in the Docker container, so you can run it with:

docker-compose run --rm php php bin/toggljira.php sync --startDate=yesterday

You can also install Composer dependencies like this, which ensures they get installed in a PHP 7.1 environment. You can ignore the git warnings; it will still work:

# NOTE: At least on Linux, this will cause the vendor files to be owned by root if your user is in the Docker group. You will have to delete them with sudo if you need to later on.

docker-compose run --rm php composer install

Thanks

I couldn't have done it without the help of Timon Bolier and from the community, wizonesolutions for his Docker implementation :)

toggl-jira's People

Contributors

axalian avatar tbolier avatar wizonesolutions avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

toggl-jira's Issues

Allow colon after issue ID in Toggl logs

Is your feature request related to a problem? Please describe.
I wish I could use this format for Toggl log entries:

ABCD-1234: Reticulate splines.

The colon means that it gets parsed as ['ABCD', '1234:'], though, and the issue is not found.

Describe alternatives you've considered
I have just been omitting the colon.

Use /myself instead of /user in getUser()

Describe the bug
The JIRA API has deprecated usernames (and user keys too, for that matter).

Additional context
In my local copy, I simply switched to the /rest/api/2/myself endpoint in \TogglJira\Jira\Api::getUser(), which doesn't need any arguments. That worked fine and fixed the script. I think this is a reasonable fix given the use cases. The alternative would be to require the accountId in config. It's not necessarily as easy to find that in the UI, though.

I will try to rebase on master and send a PR sometime.

Crashes on single-word Toggl logs

Describe the bug
Toggl entries like ABCD-1234 will cause the script to crash because it expects a description on the right-hand side of the split string, but this causes the right-hand side to be NULL.

Application exception:
======================================================================
The application has thrown an exception!
======================================================================

TypeError:
explode() expects parameter 2 to be string, null given
0
/usr/src/toggl-jira/module/TogglJira/src/Service/SyncService.php
212
#0 /usr/src/toggl-jira/module/TogglJira/src/Service/SyncService.php(212): explode(' ', NULL)
#1 /usr/src/toggl-jira/module/TogglJira/src/Service/SyncService.php(179): TogglJira\Service\SyncService->parseTimeEntry(Array)
#2 /usr/src/toggl-jira/module/TogglJira/src/Service/SyncService.php(126): TogglJira\Service\SyncService->parseTimeEntries(Array)
#3 /usr/src/toggl-jira/module/TogglJira/src/Command/SyncCommand.php(64): TogglJira\Service\SyncService->sync(Object(DateTime), Object(DateTime), false)
#4 /usr/src/toggl-jira/module/TogglJira/src/Handler/CommandHandler.php(55): TogglJira\Command\SyncCommand->execute(Object(Zend\Console\Request), Object(Zend\Console\Adapter\Posix))
#5 [internal function]: TogglJira\Handler\CommandHandler->__invoke(Object(ZF\Console\Route), Object(Zend\Console\Adapter\Posix))
#6 /usr/src/toggl-jira/vendor/zfcampus/zf-console/src/Dispatcher.php(107): call_user_func(Object(TogglJira\Handler\CommandHandler), Object(ZF\Console\Route), Object(Zend\Console\Adapter\Posix))
#7 /usr/src/toggl-jira/vendor/zfcampus/zf-console/src/Application.php(215): ZF\Console\Dispatcher->dispatch(Object(ZF\Console\Route), Object(Zend\Console\Adapter\Posix))
#8 /usr/src/toggl-jira/vendor/zfcampus/zf-console/src/Application.php(168): ZF\Console\Application->processRun(Array)
#9 /usr/src/toggl-jira/bin/toggljira.php(11): ZF\Console\Application->run()
#10 {main}

To Reproduce
Steps to reproduce the behavior:

  1. Create an entry like the above in Toggl and sync it.
  2. Run the script with a --start option that includes the date of the Toggl entry.

Expected behavior
Script runs and entries are synced. If there is no ABCD-1234 issue in JIRA, the script still syncs other time logs.

Additional context
I was able to work around this by just editing the Toggl entries that caused it. I'm thinking a good solution would be an additional configuration option to specify which projects should be synced. Alternatively, the script could query JIRA to check which projects at the configured URL the user actually has access to (and their issue prefixes) and then discard any non-matching time logs. I might try to do this if I keep bumping up against this. Thought to just file a bug report for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.