Skip to content

Commit 5d2b8b7

Browse files
committed
updated queries
1 parent 3aaa98a commit 5d2b8b7

File tree

2 files changed

+78
-25
lines changed

2 files changed

+78
-25
lines changed

scripts/sql/12_gitlab_webhook.down.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
DELETE FROM git_host_webhook_event_selectors where event_id in (5,6)
18-
DELETE FROM git_host_webhook_event where git_host_id=3
17+
DELETE FROM git_host_webhook_event_selectors where event_id in (select id from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name in 'Pull Request', 'Tag Creation')
18+
DELETE FROM git_host_webhook_event where git_host_name='Gitlab_Devtron';
19+
ALTER TABLE git_host_webhook_event DROP COLUMN git_host_name;
20+
ALTER TABLE git_host_webhook_event ALTER COLUMN git_host_id SET NOT NULL;

scripts/sql/12_gitlab_webhook.up.sql

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,92 @@ INSERT INTO git_host_webhook_event (git_host_name, name, event_types_csv,
2222
VALUES ('Gitlab_Devtron', 'Pull Request', 'Merge Request Hook', 'non-merged','t', NOW()),
2323
('Gitlab_Devtron', 'Tag Creation', 'Tag Push Hook', 'merged','t', NOW());
2424

25+
-- pr queries
2526
INSERT INTO git_host_webhook_event_selectors
2627
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
27-
VALUES (5, 'unique id', 'object_attributes.id', 'f', 'f', 't', NULL, NOW()),
28-
(5, 'repository url', 'project.http_url', 'f', 'f', 't', NULL, NOW()),
29-
(5, 'title', 'object_attributes.title', 't', 't', 't', NULL, NOW()),
30-
(5, 'git url', 'object_attributes.url', 't', 'f', 't', NULL, NOW()),
31-
(5, 'author', 'user.username', 't', 't', 't', NULL, NOW()),
32-
(5, 'date', 'object_attributes.updated_at', 't', 'f', 't', NULL, NOW()),
33-
(5, 'source checkout', 'object_attributes.last_commit.id', 't', 'f', 't', NULL, NOW()),
34-
(5, 'target branch name', 'object_attributes.target_branch', 't', 't', 't', NULL, NOW()),
35-
(5, 'source branch name', 'object_attributes.source_branch', 't', 't', 't', NULL, NOW()),
36-
(5, 'repository ssh url', 'project.ssh_url', 't', 't', 't', NULL, NOW()),
37-
(5, 'description', 'object_attributes.description', 't', 't', 't', NULL, NOW()),
38-
(5, 'state', 'object_attributes.state', 't', 't', 't', 'opened', NOW());
28+
select id, 'unique id', 'object_attributes.id', 'f', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
3929

30+
INSERT INTO git_host_webhook_event_selectors
31+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
32+
select id, 'repository url', 'project.http_url', 'f', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
33+
34+
INSERT INTO git_host_webhook_event_selectors
35+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
36+
select id, 'title', 'object_attributes.title', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
37+
38+
INSERT INTO git_host_webhook_event_selectors
39+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
40+
select id, 'git url', 'object_attributes.url', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
41+
42+
INSERT INTO git_host_webhook_event_selectors
43+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
44+
select id, 'author', 'user.username', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
45+
46+
INSERT INTO git_host_webhook_event_selectors
47+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
48+
select id, 'date', 'object_attributes.updated_at', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
49+
50+
INSERT INTO git_host_webhook_event_selectors
51+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
52+
select id, 'source checkout', 'object_attributes.last_commit.id', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
53+
54+
INSERT INTO git_host_webhook_event_selectors
55+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
56+
select id, 'target branch name', 'object_attributes.target_branch', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
57+
58+
INSERT INTO git_host_webhook_event_selectors
59+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
60+
select id, 'source branch name', 'object_attributes.source_branch', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
61+
62+
INSERT INTO git_host_webhook_event_selectors
63+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
64+
select id, 'repository ssh url', 'project.ssh_url', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
65+
66+
INSERT INTO git_host_webhook_event_selectors
67+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
68+
select id, 'description', 'object_attributes.description', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
69+
70+
INSERT INTO git_host_webhook_event_selectors
71+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
72+
select id, 'state', 'object_attributes.state', 't', 't', 't', 'opened', NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request';
73+
74+
-- tag queries
75+
76+
INSERT INTO git_host_webhook_event_selectors
77+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
78+
select id, 'repository url', 'project.web_url', 'f', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
79+
80+
INSERT INTO git_host_webhook_event_selectors
81+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
82+
select id, 'author', 'user_username', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
83+
84+
INSERT INTO git_host_webhook_event_selectors
85+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
86+
select id, 'date', 'object_attributes.updated_at', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
87+
88+
INSERT INTO git_host_webhook_event_selectors
89+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
90+
select id, 'tag name', 'ref', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
91+
92+
INSERT INTO git_host_webhook_event_selectors
93+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
94+
select id, 'target checkout', 'checkout_sha', 't', 'f', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
95+
96+
INSERT INTO git_host_webhook_event_selectors
97+
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
98+
select id, 'tag creation identifier', 'checkout_sha', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
4099

41100
INSERT INTO git_host_webhook_event_selectors
42101
(event_id, name, selector, to_show, to_show_in_ci_filter, is_active, possible_values, created_on)
43-
VALUES
44-
(6, 'repository url', 'project.web_url', 'f', 'f', 't', NULL, NOW()),
45-
(6, 'author', 'user_username', 't', 't', 't', NULL, NOW()),
46-
(6, 'date', 'object_attributes.updated_at', 't', 'f', 't', NULL, NOW()),
47-
(6, 'tag name', 'ref', 't', 'f', 't', NULL, NOW()),
48-
(6, 'target checkout', 'checkout_sha', 't', 'f', 't', NULL, NOW()),
49-
(6, 'tag creation identifier', 'checkout_sha', 't', 't', 't', NULL, NOW()),
50-
(6, 'repository ssh url', 'project.ssh_url', 't', 't', 't', NULL, NOW());
102+
select id, 'repository ssh url', 'project.ssh_url', 't', 't', 't', NULL, NOW() from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation';
51103

52104

53105
--- set fix_value for gitlab pull_request state
54106
update git_host_webhook_event_selectors
55107
set fix_value = '^opened$'
56-
where event_id = 5
57-
and name = 'state';
108+
where event_id = (select id from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Pull Request') and name = 'state';
58109

59110
--- set fix_value for gitlab tag creation identifier ref_type
60111
update git_host_webhook_event_selectors
61112
set fix_value = '\b[0-9a-f]{5,40}\b'
62-
where event_id=6 and name='tag creation identifier';
113+
where event_id= (select id from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name='Tag Creation') and name='tag creation identifier';

0 commit comments

Comments
 (0)