Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.sonar.db.ai.CsAiRuleCatalogDto;
import org.sonar.db.ai.CsAiRulesCatalogMapper;
import org.sonar.db.alm.pat.AlmPatMapper;
import org.sonar.db.alm.setting.AlmSettingMapper;
import org.sonar.db.alm.setting.ProjectAlmKeyAndProject;
Expand Down Expand Up @@ -221,6 +223,7 @@ public void start() {
confBuilder.loadAlias("AnticipatedTransition", AnticipatedTransitionDto.class);
confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class);
confBuilder.loadAlias("Component", ComponentDto.class);
confBuilder.loadAlias("CsAiRuleCatalog", CsAiRuleCatalogDto.class);
confBuilder.loadAlias("Cve", CveDto.class);
confBuilder.loadAlias("CveCwe", CveCweDto.class);
confBuilder.loadAlias("DevOpsPermissionsMapping", DevOpsPermissionsMappingDto.class);
Expand Down Expand Up @@ -303,6 +306,7 @@ public void start() {
CeTaskMessageMapper.class,
ComponentKeyUpdaterMapper.class,
ComponentMapper.class,
CsAiRulesCatalogMapper.class,
CveMapper.class,
CveCweMapper.class,
DefaultQProfileMapper.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SonarQube
* Copyright (C) 2009-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.ai;

public class CsAiRuleCatalogDto {

private String ruleKey;
private String language;
private String description;
private String contextSeverity;

public String getRuleKey() {
return ruleKey;
}

public CsAiRuleCatalogDto setRuleKey(String ruleKey) {
this.ruleKey = ruleKey;
return this;
}

public String getLanguage() {
return language;
}

public CsAiRuleCatalogDto setLanguage(String language) {
this.language = language;
return this;
}

public String getDescription() {
return description;
}

public CsAiRuleCatalogDto setDescription(String description) {
this.description = description;
return this;
}

public String getContextSeverity() {
return contextSeverity;
}

public CsAiRuleCatalogDto setContextSeverity(String contextSeverity) {
this.contextSeverity = contextSeverity;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SonarQube
* Copyright (C) 2009-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* SonarQube
*/
package org.sonar.db.ai;

import org.apache.ibatis.annotations.Param;

public interface CsAiRulesCatalogMapper {

CsAiRuleCatalogDto selectByRuleKey(@Param("language") String language, @Param("ruleKey") String ruleKey);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SonarQube
* Copyright (C) 2009-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.ai;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.sonar.db.ai.CsAiRulesCatalogMapper">

<resultMap id="RuleCatalogResult" type="org.sonar.db.ai.CsAiRuleCatalogDto">
<result column="rule_key" property="ruleKey"/>
<result column="language" property="language"/>
<result column="description" property="description"/>
<result column="context_severity" property="contextSeverity"/>
</resultMap>

<select id="selectByRuleKey" parameterType="string" resultMap="RuleCatalogResult">
select rule_key, language, description, context_severity
from cs_ai_rules_catalog
where rule_key = #{ruleKey} and language = #{language}
</select>

</mapper>
14 changes: 14 additions & 0 deletions server/sonar-web/src/main/js/api/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ import {
} from '../types/issues';
import { Dict, FacetValue, IssueChangelog, SnippetsByComponent, SourceLine } from '../types/types';

export type IssueContextResponse = {
componentKey?: string;
contextSeverity?: 'LOW' | 'MEDIUM' | 'HIGH';
issueKey: string;
line: number;
ruleDescription?: string;
ruleKey?: string;
snippet: string;
};

export function searchIssues(query: RequestData): Promise<RawIssuesResponse> {
return getJSON('/api/issues/search', query).catch(error => {
if (error?.status === 403 ) {
Expand Down Expand Up @@ -170,3 +180,7 @@ export function getIssueFlowSnippets(issueKey: string): Promise<Dict<SnippetsByC
return result;
});
}

export function getIssueContext(data: {componentKey?: string; contextSeverity?: 'LOW' | 'MEDIUM' | 'HIGH'; issue: string; rule?: string;}): Promise<IssueContextResponse> {
return getJSON('/api/issues/context', data).catch(throwGlobalError);
}
Loading