Automattic / ghactivity

WordPress plugin. Build reports of all your GitHub activity.
https://wordpress.org/plugins/ghactivity/
6 stars 2 forks source link

Track label events in label taxonomy meta #13

Closed brbrr closed 6 years ago

brbrr commented 6 years ago

This PR adds underlying functionality for https://github.com/Automattic/ghactivity/issues/3

It adds a possibility to record any label-related actions into label taxonomy.

Context:

There is a cron job which is fetching repo & user events (like PR/issue open/closed, comment added, commits added etc) and create relevant GitHub Event custom post type. In case of Issue/PR event - it also creates GitHub Issue CPT, where a bunch of different data (together with a list of labels) is stored as taxonomies. The problem is that used API endpoints return only a limited range of Issue/PR event types (only created & closed), which means it not possible to track any label changes.

There is /repos/repo_name/issues/events endpoint which returns all the issue related events, but its schema differs from the endpoints mentioned above.

How things work:

Every time when cron job is triggered - this plugin will fetch /repos/repo_name/issues/events to get all the issue/PR related events (after other events were processed). For every labeled or unlabeled event it updates Issue Event label taxonomy (ghactivity_issues_labels) by adding term metadata such as: status, labeled, unlabeled. Label taxonomies are not unique, so to be able to distinguish one issue labels metadata from another I come up with this structure:

$slug = $repo_name . '#' . $issue_number; // e.g. automattic/ghactivity#13
$record = [
     "status" => [
       "labeled",
     ],
     "labeled" => [
       "2018-07-19T11:28:50Z",
     ],
     "unlabeled" => [
       "2018-07-19T10:10:44Z",
     ],
   ];

update_term_meta( $term_id, $slug, $record );

So now, any label which is used in multiple issues/repos will have metadata for every specific issue

Also, this PR includes some refactoring and nesting simplifications.

To test:

cron job may take 1-2 min to finish.

brbrr commented 6 years ago

Closing in favor #14 which is simplified version of this PR