Skip to content

Commit c3c1407

Browse files
authored
feat: Codacy plugin integration (#2892)
* added migration for codacy plugin * updated migration value with default null value * updated api token variable name * updated migration script to use gloabal variable * added codacy plugin rollback * added icon for codacy * updated description and icon url for codacy plugin * udated description for API Token
1 parent e093951 commit c3c1407

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

assets/codacy-plugin-icon.png

1.51 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DELETE FROM plugin_step_variable WHERE name = 'CodacyEndpoint'
2+
DELETE FROM plugin_step_variable WHERE name = 'GitProvider'
3+
DELETE FROM plugin_step_variable WHERE name = 'CodacyApiToken'
4+
DELETE FROM plugin_step_variable WHERE name = 'Organisation'
5+
DELETE FROM plugin_step_variable WHERE name = 'RepoName'
6+
DELETE FROM plugin_step_variable WHERE name = 'Branch'
7+
DELETE FROM plugin_step_variable WHERE name = 'NUMBER_OF_ISSUES'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
INSERT INTO plugin_metadata (id,name,description,type,icon,deleted,created_on,created_by,updated_on,updated_by)
2+
VALUES (nextval('id_seq_plugin_metadata'),'Codacy','Codacy is an automated code analysis/quality tool that helps developers ship better software, faster.','PRESET','https://raw.githubusercontent.com/devtron-labs/devtron/main/assets/codacy-plugin-icon.png',false,'now()',1,'now()',1);
3+
4+
INSERT INTO plugin_pipeline_script (id,script,type,deleted,created_on,created_by,updated_on,updated_by)
5+
VALUES (nextval('id_seq_plugin_pipeline_script'),E'if [[ ! -z "$CodacyApiToken" ]]
6+
then
7+
CODACY_API_TOKEN=$CodacyApiToken
8+
fi
9+
data_raw="{\\\"branchName\\\":\\\"$Branch\\\",\\\"categories\\\":[\\\"Security\\\"],\\\"levels\\\":[\\\"Error\\\"]}"
10+
raw_url="curl -X POST \\\"$CodacyEndpoint/api/v3/analysis/organizations/$GitProvider/$Organisation/repositories/$RepoName/issues/search\\\" -H \\\"Content-Type:application/json\\\" -H \\\"api-token:$CODACY_API_TOKEN\\\" --data-raw \'$data_raw\'"
11+
result=`eval $raw_url`
12+
echo $result
13+
export NUMBER_OF_ISSUES=$(echo $result | jq -r ".data | length")
14+
echo "***********number of issue***********"
15+
echo "Number of issues are: $NUMBER_OF_ISSUES"
16+
echo "***********number of issue***********"
17+
if [ "$NUMBER_OF_ISSUES" -gt "0" ]
18+
then
19+
echo "This code has critical Vulnerabilities . Visit https://app.codacy.com/gh/delhivery/$REPO/issues for more Info"
20+
else
21+
exit 0
22+
fi','SHELL',false,'now()',1,'now()',1);
23+
24+
INSERT INTO plugin_step (id,plugin_id,name,description,index,step_type,script_id,ref_plugin_id,output_directory_path,dependent_on_step,deleted,created_on,created_by,updated_on,updated_by)
25+
VALUES (nextval('id_seq_plugin_step'),(SELECT id FROM plugin_metadata WHERE name='Codacy'),'Step 1','Step 1 for Codacy',1,'INLINE',(SELECT last_value FROM id_seq_plugin_pipeline_script),null,null,null,false,'now()',1,'now()',1);
26+
27+
INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by)
28+
VALUES (nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'CodacyEndpoint','STRING','Api Endpoint for Codacy','t','f',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
29+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'GitProvider','STRING','Git provider for the scan','t','f',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
30+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'CodacyApiToken','STRING','If provided, this token will be used. If not provided it will be picked from global secret(CODACY_API_TOKEN)','t','t',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
31+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'Organisation','STRING','Org for the Codacy','t','f',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
32+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'RepoName','STRING','Repo name','t','f',false,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
33+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'Branch','STRING','Branch name ','t','f',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1),
34+
(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Codacy' and ps."index"=1 and ps.deleted=false),'NUMBER_OF_ISSUES','STRING','Number of issue in code source','t','f',false,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1);
35+
36+
37+
INSERT INTO plugin_tag (id,name,deleted,created_on,created_by,updated_on,updated_by)
38+
VALUES (nextval('id_seq_plugin_tag'),'Code Review',false,'now()',1,'now()',1);
39+
40+
INSERT INTO plugin_tag_relation (id,tag_id,plugin_id,created_on,created_by,updated_on,updated_by)
41+
VALUES (nextval('id_seq_plugin_tag_relation'),2,(SELECT id FROM plugin_metadata WHERE name='Codacy'),'now()',1,'now()',1),
42+
(nextval('id_seq_plugin_tag_relation'),3,(SELECT id FROM plugin_metadata WHERE name='Codacy'),'now()',1,'now()',1),
43+
(nextval('id_seq_plugin_tag_relation'),(SeLECT id FROM plugin_tag WHERE name='Code Review'),(SELECT id FROM plugin_metadata WHERE name='Codacy'),'now()',1,'now()',1);

0 commit comments

Comments
 (0)