Skip to content

Commit 0eef834

Browse files
authored
Use project-relative path when calculating gitlab message fingerprint (#11532)
## Summary Concurrent GitLab runners clone projects into separate directories, e.g. `{builds_dir}/$RUNNER_TOKEN_KEY/$CONCURRENT_ID/$NAMESPACE/$PROJECT_NAME`. Since the fingerprint uses the full path to the file, the fingerprints calculated by Ruff are different depending on which concurrent runner it executes on, so often an MR will appear to remove all existing issues and add them with new fingerprints. I've adjusted the fingerprint function to use the project relative path, which fixes this. Unfortunately this will have a breaking change for any current users of this output - the fingerprints will change and appear in GitLab as all linting messages having been fixed and then created. ## Test Plan `cargo nextest run` Running `ruff check --output-format gitlab` in a git repo, moving the repo and running again, verifying no diffs between the outputs
1 parent 650c578 commit 0eef834

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crates/ruff_linter/src/message/gitlab.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ impl Serialize for SerializedMessages<'_> {
8282
|project_dir| relativize_path_to(message.filename(), project_dir),
8383
);
8484

85-
let mut message_fingerprint = fingerprint(message, 0);
85+
let mut message_fingerprint = fingerprint(message, &path, 0);
8686

8787
// Make sure that we do not get a fingerprint that is already in use
8888
// by adding in the previously generated one.
8989
while fingerprints.contains(&message_fingerprint) {
90-
message_fingerprint = fingerprint(message, message_fingerprint);
90+
message_fingerprint = fingerprint(message, &path, message_fingerprint);
9191
}
9292
fingerprints.insert(message_fingerprint);
9393

@@ -109,20 +109,20 @@ impl Serialize for SerializedMessages<'_> {
109109
}
110110

111111
/// Generate a unique fingerprint to identify a violation.
112-
fn fingerprint(message: &Message, salt: u64) -> u64 {
112+
fn fingerprint(message: &Message, project_path: &str, salt: u64) -> u64 {
113113
let Message {
114114
kind,
115115
range: _,
116116
fix: _fix,
117-
file,
117+
file: _,
118118
noqa_offset: _,
119119
} = message;
120120

121121
let mut hasher = DefaultHasher::new();
122122

123123
salt.hash(&mut hasher);
124124
kind.name.hash(&mut hasher);
125-
file.name().hash(&mut hasher);
125+
project_path.hash(&mut hasher);
126126

127127
hasher.finish()
128128
}

0 commit comments

Comments
 (0)