Add Azure Devops as a -format option. (#3335)

This commit is contained in:
StefanBRas 2023-03-06 03:48:39 +01:00 committed by GitHub
parent 5d8591fec4
commit 30c71dc59a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 6 deletions

View file

@ -194,7 +194,7 @@ pub struct Options {
pub fixable: Option<Vec<RuleSelector>>,
#[option(
default = r#""text""#,
value_type = r#""text" | "json" | "junit" | "github" | "gitlab" | "pylint""#,
value_type = r#""text" | "json" | "junit" | "github" | "gitlab" | "pylint" | "azure""#,
example = r#"
# Group violations by containing file.
format = "grouped"
@ -203,8 +203,8 @@ pub struct Options {
/// The style in which violation messages should be formatted: `"text"`
/// (default), `"grouped"` (group messages by file), `"json"`
/// (machine-readable), `"junit"` (machine-readable XML), `"github"` (GitHub
/// Actions annotations), `"gitlab"` (GitLab CI code quality report), or
/// `"pylint"` (Pylint text format).
/// Actions annotations), `"gitlab"` (GitLab CI code quality report),
/// `"pylint"` (Pylint text format) or `"azure"` (Azure Pipeline logging commands).
pub format: Option<SerializationFormat>,
#[option(
default = r#"false"#,

View file

@ -216,6 +216,7 @@ pub enum SerializationFormat {
Github,
Gitlab,
Pylint,
Azure,
}
impl Default for SerializationFormat {

View file

@ -374,6 +374,33 @@ impl Printer {
writeln!(stdout, "{label}")?;
}
}
SerializationFormat::Azure => {
// Generate error logging commands for Azure Pipelines format.
// See https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#logissue-log-an-error-or-warning
for message in &diagnostics.messages {
let label = format!(
"{}{}{}{}{}{} {} {}",
relativize_path(Path::new(&message.filename)),
":",
message.location.row(),
":",
message.location.column(),
":",
message.kind.rule().noqa_code(),
message.kind.body(),
);
writeln!(
stdout,
"##vso[task.logissue type=error\
;sourcepath={};linenumber={};columnnumber={};code={};]{}",
message.filename,
message.location.row(),
message.location.column(),
message.kind.rule().noqa_code(),
label,
)?;
}
}
}
stdout.flush()?;

View file

@ -209,7 +209,7 @@ Options:
--ignore-noqa
Ignore any `# noqa` comments
--format <FORMAT>
Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint]
Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint, azure]
--target-version <TARGET_VERSION>
The minimum Python version that should be supported
--config <CONFIG>

5
ruff.schema.json generated
View file

@ -272,7 +272,7 @@
]
},
"format": {
"description": "The style in which violation messages should be formatted: `\"text\"` (default), `\"grouped\"` (group messages by file), `\"json\"` (machine-readable), `\"junit\"` (machine-readable XML), `\"github\"` (GitHub Actions annotations), `\"gitlab\"` (GitLab CI code quality report), or `\"pylint\"` (Pylint text format).",
"description": "The style in which violation messages should be formatted: `\"text\"` (default), `\"grouped\"` (group messages by file), `\"json\"` (machine-readable), `\"junit\"` (machine-readable XML), `\"github\"` (GitHub Actions annotations), `\"gitlab\"` (GitLab CI code quality report), `\"pylint\"` (Pylint text format) or `\"azure\"` (Azure Pipeline logging commands).",
"anyOf": [
{
"$ref": "#/definitions/SerializationFormat"
@ -2178,7 +2178,8 @@
"grouped",
"github",
"gitlab",
"pylint"
"pylint",
"azure"
]
},
"Strictness": {