Skip to content

Commit 6b46248

Browse files
committed
feature #152 Update milestone to "next" (Nyholm)
This PR was merged into the master branch. Discussion ---------- Update milestone to "next" FYI @OskarStark Commits ------- f771123 Update milestone to "next"
2 parents ee145ed + f771123 commit 6b46248

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-0
lines changed

config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ parameters:
2727
- 'App\Subscriber\UnsupportedBranchSubscriber'
2828
- 'subscriber.symfony_docs.milestone'
2929
- 'App\Subscriber\RemoveStalledLabelOnCommentSubscriber'
30+
- 'App\Subscriber\UpdateMilestoneWhenLabeledWaitingCodeMergeSubscriber'
3031
secret: '%env(SYMFONY_DOCS_SECRET)%'
3132

3233
# used in a functional test
@@ -44,6 +45,7 @@ parameters:
4445
- 'App\Subscriber\CloseDraftPRSubscriber'
4546
- 'App\Subscriber\UnsupportedBranchSubscriber'
4647
- 'App\Subscriber\RemoveStalledLabelOnCommentSubscriber'
48+
- 'App\Subscriber\UpdateMilestoneWhenLabeledWaitingCodeMergeSubscriber'
4749

4850
services:
4951
_defaults:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Subscriber;
4+
5+
use App\Api\Milestone\MilestoneApi;
6+
use App\Event\GitHubEvent;
7+
use App\GitHubEvents;
8+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9+
10+
/**
11+
* When label "Waiting Code Merge" is added, then set milestone to "next".
12+
*
13+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
14+
*/
15+
class UpdateMilestoneWhenLabeledWaitingCodeMergeSubscriber implements EventSubscriberInterface
16+
{
17+
private MilestoneApi $milestoneApi;
18+
19+
public function __construct(MilestoneApi $milestoneApi)
20+
{
21+
$this->milestoneApi = $milestoneApi;
22+
}
23+
24+
public function onLabel(GitHubEvent $event)
25+
{
26+
$data = $event->getData();
27+
$action = $data['action'];
28+
if ('labeled' !== $action) {
29+
return;
30+
}
31+
32+
foreach ($data['pull_request']['labels'] ?? $data['issue']['labels'] ?? [] as $label) {
33+
if ('Waiting Code Merge' === $label['name']) {
34+
$repository = $event->getRepository();
35+
$number = $data['number'] ?? $data['issue']['number'];
36+
$this->milestoneApi->updateMilestone($repository, $number, 'next');
37+
38+
$event->setResponseData([
39+
'pull_request' => $number,
40+
'milestone' => 'next',
41+
]);
42+
43+
return;
44+
}
45+
}
46+
}
47+
48+
public static function getSubscribedEvents()
49+
{
50+
return [
51+
GitHubEvents::PULL_REQUEST => 'onLabel',
52+
GitHubEvents::ISSUES => 'onLabel',
53+
];
54+
}
55+
}

tests/Controller/WebhookControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function getTests()
8989
'pull_request.new_contributor.json',
9090
['pull_request' => 4, 'status_change' => 'needs_review', 'pr_labels' => [], 'new_contributor' => true],
9191
],
92+
'Waiting Code Merge' => [
93+
'pull_request',
94+
'issues.labeled.waitingCodeMerge.json',
95+
['pull_request' => 2, 'milestone' => 'next'],
96+
],
9297
];
9398
}
9499
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"action": "labeled",
3+
"issue": {
4+
"url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/2",
5+
"labels_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/2/labels{/name}",
6+
"comments_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/2/comments",
7+
"events_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/2/events",
8+
"html_url": "https://github.com/carsonbot-playground/symfony/issues/2",
9+
"id": 95027129,
10+
"number": 2,
11+
"title": "Brand new issue",
12+
"user": {
13+
"login": "weaverryan",
14+
"id": 121003,
15+
"avatar_url": "https://avatars.githubusercontent.com/u/121003?v=3",
16+
"gravatar_id": "",
17+
"url": "https://api.github.com/users/weaverryan",
18+
"html_url": "https://github.com/weaverryan",
19+
"followers_url": "https://api.github.com/users/weaverryan/followers",
20+
"following_url": "https://api.github.com/users/weaverryan/following{/other_user}",
21+
"gists_url": "https://api.github.com/users/weaverryan/gists{/gist_id}",
22+
"starred_url": "https://api.github.com/users/weaverryan/starred{/owner}{/repo}",
23+
"subscriptions_url": "https://api.github.com/users/weaverryan/subscriptions",
24+
"organizations_url": "https://api.github.com/users/weaverryan/orgs",
25+
"repos_url": "https://api.github.com/users/weaverryan/repos",
26+
"events_url": "https://api.github.com/users/weaverryan/events{/privacy}",
27+
"received_events_url": "https://api.github.com/users/weaverryan/received_events",
28+
"type": "User",
29+
"site_admin": false
30+
},
31+
"labels": [
32+
{
33+
"url": "https://api.github.com/repos/carsonbot-playground/symfony/labels/Waiting%20Code%20Merge",
34+
"name": "Waiting Code Merge",
35+
"color": "fc2929"
36+
}
37+
],
38+
"state": "open",
39+
"locked": false,
40+
"assignee": null,
41+
"milestone": null,
42+
"comments": 0,
43+
"created_at": "2015-07-14T20:00:15Z",
44+
"updated_at": "2015-07-14T20:00:19Z",
45+
"closed_at": null,
46+
"body": ""
47+
},
48+
"label": {
49+
"url": "https://api.github.com/repos/carsonbot-playground/symfony/labels/bug",
50+
"name": "bug",
51+
"color": "fc2929"
52+
},
53+
"repository": {
54+
"id": 21151556,
55+
"name": "symfony",
56+
"full_name": "carsonbot-playground/symfony",
57+
"owner": {
58+
"login": "weaverryan",
59+
"id": 121003,
60+
"avatar_url": "https://avatars.githubusercontent.com/u/121003?v=3",
61+
"gravatar_id": "",
62+
"url": "https://api.github.com/users/weaverryan",
63+
"html_url": "https://github.com/weaverryan",
64+
"followers_url": "https://api.github.com/users/weaverryan/followers",
65+
"following_url": "https://api.github.com/users/weaverryan/following{/other_user}",
66+
"gists_url": "https://api.github.com/users/weaverryan/gists{/gist_id}",
67+
"starred_url": "https://api.github.com/users/weaverryan/starred{/owner}{/repo}",
68+
"subscriptions_url": "https://api.github.com/users/weaverryan/subscriptions",
69+
"organizations_url": "https://api.github.com/users/weaverryan/orgs",
70+
"repos_url": "https://api.github.com/users/weaverryan/repos",
71+
"events_url": "https://api.github.com/users/weaverryan/events{/privacy}",
72+
"received_events_url": "https://api.github.com/users/weaverryan/received_events",
73+
"type": "User",
74+
"site_admin": false
75+
},
76+
"private": false,
77+
"html_url": "https://github.com/carsonbot-playground/symfony",
78+
"description": "The Symfony PHP framework",
79+
"fork": true,
80+
"url": "https://api.github.com/repos/carsonbot-playground/symfony",
81+
"forks_url": "https://api.github.com/repos/carsonbot-playground/symfony/forks",
82+
"keys_url": "https://api.github.com/repos/carsonbot-playground/symfony/keys{/key_id}",
83+
"collaborators_url": "https://api.github.com/repos/carsonbot-playground/symfony/collaborators{/collaborator}",
84+
"teams_url": "https://api.github.com/repos/carsonbot-playground/symfony/teams",
85+
"hooks_url": "https://api.github.com/repos/carsonbot-playground/symfony/hooks",
86+
"issue_events_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/events{/number}",
87+
"events_url": "https://api.github.com/repos/carsonbot-playground/symfony/events",
88+
"assignees_url": "https://api.github.com/repos/carsonbot-playground/symfony/assignees{/user}",
89+
"branches_url": "https://api.github.com/repos/carsonbot-playground/symfony/branches{/branch}",
90+
"tags_url": "https://api.github.com/repos/carsonbot-playground/symfony/tags",
91+
"blobs_url": "https://api.github.com/repos/carsonbot-playground/symfony/git/blobs{/sha}",
92+
"git_tags_url": "https://api.github.com/repos/carsonbot-playground/symfony/git/tags{/sha}",
93+
"git_refs_url": "https://api.github.com/repos/carsonbot-playground/symfony/git/refs{/sha}",
94+
"trees_url": "https://api.github.com/repos/carsonbot-playground/symfony/git/trees{/sha}",
95+
"statuses_url": "https://api.github.com/repos/carsonbot-playground/symfony/statuses/{sha}",
96+
"languages_url": "https://api.github.com/repos/carsonbot-playground/symfony/languages",
97+
"stargazers_url": "https://api.github.com/repos/carsonbot-playground/symfony/stargazers",
98+
"contributors_url": "https://api.github.com/repos/carsonbot-playground/symfony/contributors",
99+
"subscribers_url": "https://api.github.com/repos/carsonbot-playground/symfony/subscribers",
100+
"subscription_url": "https://api.github.com/repos/carsonbot-playground/symfony/subscription",
101+
"commits_url": "https://api.github.com/repos/carsonbot-playground/symfony/commits{/sha}",
102+
"git_commits_url": "https://api.github.com/repos/carsonbot-playground/symfony/git/commits{/sha}",
103+
"comments_url": "https://api.github.com/repos/carsonbot-playground/symfony/comments{/number}",
104+
"issue_comment_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues/comments{/number}",
105+
"contents_url": "https://api.github.com/repos/carsonbot-playground/symfony/contents/{+path}",
106+
"compare_url": "https://api.github.com/repos/carsonbot-playground/symfony/compare/{base}...{head}",
107+
"merges_url": "https://api.github.com/repos/carsonbot-playground/symfony/merges",
108+
"archive_url": "https://api.github.com/repos/carsonbot-playground/symfony/{archive_format}{/ref}",
109+
"downloads_url": "https://api.github.com/repos/carsonbot-playground/symfony/downloads",
110+
"issues_url": "https://api.github.com/repos/carsonbot-playground/symfony/issues{/number}",
111+
"pulls_url": "https://api.github.com/repos/carsonbot-playground/symfony/pulls{/number}",
112+
"milestones_url": "https://api.github.com/repos/carsonbot-playground/symfony/milestones{/number}",
113+
"notifications_url": "https://api.github.com/repos/carsonbot-playground/symfony/notifications{?since,all,participating}",
114+
"labels_url": "https://api.github.com/repos/carsonbot-playground/symfony/labels{/name}",
115+
"releases_url": "https://api.github.com/repos/carsonbot-playground/symfony/releases{/id}",
116+
"created_at": "2014-06-24T04:00:07Z",
117+
"updated_at": "2015-06-28T12:37:42Z",
118+
"pushed_at": "2015-06-28T15:31:08Z",
119+
"git_url": "git://github.com/carsonbot-playground/symfony.git",
120+
"ssh_url": "git@github.com:carsonbot-playground/symfony.git",
121+
"clone_url": "https://github.com/carsonbot-playground/symfony.git",
122+
"svn_url": "https://github.com/carsonbot-playground/symfony",
123+
"homepage": "symfony.com",
124+
"size": 55804,
125+
"stargazers_count": 0,
126+
"watchers_count": 0,
127+
"language": "PHP",
128+
"has_issues": true,
129+
"has_downloads": false,
130+
"has_wiki": false,
131+
"has_pages": false,
132+
"forks_count": 0,
133+
"mirror_url": null,
134+
"open_issues_count": 4,
135+
"forks": 0,
136+
"open_issues": 4,
137+
"watchers": 0,
138+
"default_branch": "master"
139+
},
140+
"sender": {
141+
"login": "weaverryan",
142+
"id": 121003,
143+
"avatar_url": "https://avatars.githubusercontent.com/u/121003?v=3",
144+
"gravatar_id": "",
145+
"url": "https://api.github.com/users/weaverryan",
146+
"html_url": "https://github.com/weaverryan",
147+
"followers_url": "https://api.github.com/users/weaverryan/followers",
148+
"following_url": "https://api.github.com/users/weaverryan/following{/other_user}",
149+
"gists_url": "https://api.github.com/users/weaverryan/gists{/gist_id}",
150+
"starred_url": "https://api.github.com/users/weaverryan/starred{/owner}{/repo}",
151+
"subscriptions_url": "https://api.github.com/users/weaverryan/subscriptions",
152+
"organizations_url": "https://api.github.com/users/weaverryan/orgs",
153+
"repos_url": "https://api.github.com/users/weaverryan/repos",
154+
"events_url": "https://api.github.com/users/weaverryan/events{/privacy}",
155+
"received_events_url": "https://api.github.com/users/weaverryan/received_events",
156+
"type": "User",
157+
"site_admin": false
158+
}
159+
}

0 commit comments

Comments
 (0)