Skip to content

Commit 2a73a6d

Browse files
committed
add github link to yml files.
1 parent 48c333e commit 2a73a6d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

devtools/text-optimizer/src/yaml_processor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::{
44
GITHUB_REPO,
55
};
66
use serde::{Deserialize, Serialize};
7-
use std::io::Read;
87
use std::io::Write;
98
use std::{fs::File, path::PathBuf};
9+
use std::{io::Read, path::Path};
1010

1111
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
1212
pub struct TextInfoSave {
@@ -17,10 +17,13 @@ pub struct TextInfoSave {
1717

1818
impl TextInfoSave {
1919
pub fn from_text_info(text_info: TextInfo, git_repo: &str, commit_id: &str) -> Self {
20-
// 使用 Metadata 的 from_meta 方法进行 Meta 到 Metadata 的转换
21-
let metadata = Metadata::from_meta(text_info.metadata(), git_repo, commit_id);
20+
let metadata = Metadata::from_meta(
21+
text_info.metadata(),
22+
git_repo,
23+
commit_id,
24+
text_info.metadata().file(),
25+
);
2226

23-
// 创建 TextInfoSave 结构体并返回
2427
TextInfoSave {
2528
original: text_info.original().to_owned(),
2629
editable: text_info.editable().to_owned(),
@@ -37,12 +40,9 @@ pub struct Metadata {
3740
}
3841

3942
impl Metadata {
40-
// 定义从 Meta 到 Metadata 的转换方法
41-
pub fn from_meta(meta: &Meta, github_repo: &str, commit_id: &str) -> Self {
42-
// 创建 GitHub 代码行链接的前缀
43-
let github_link_prefix = format!("{}/{}/", github_repo, commit_id);
44-
45-
// 为每个代码行生成 GitHub 链接
43+
pub fn from_meta(meta: &Meta, github_repo: &str, commit_id: &str, file: &Path) -> Self {
44+
let file = file.strip_prefix("../..").expect("strip prefix");
45+
let github_link_prefix = format!("{}/{}/{}", github_repo, commit_id, file.display());
4646
let code_line_link: Vec<String> = meta
4747
.start_lines()
4848
.iter()

0 commit comments

Comments
 (0)