@@ -9,6 +9,7 @@ use crate::{
99 } ,
1010 condition:: Action ,
1111 error:: Error ,
12+ github:: GitHubInfo ,
1213 repo:: { pr_issue_url, resources:: RepoResources } ,
1314 utils:: empty_or_start_new_line,
1415} ;
@@ -118,19 +119,22 @@ pub fn branch_check_message(
118119 branch : & str ,
119120 settings : & BranchSettings ,
120121 result : & BranchCheckResult ,
122+ github_info : Option < & GitHubInfo > ,
121123) -> String {
122124 let status = if result. old == result. new {
123125 format ! (
124126 "{}
125127\\ (not changed\\ )",
126- markdown_optional_commit( result. new. as_deref( ) )
128+ markdown_optional_commit( result. new. as_deref( ) , github_info )
127129 )
130+ } else if let ( Some ( info) , Some ( old) , Some ( new) ) = ( github_info, & result. old , & result. new ) {
131+ github_commit_diff ( info, old, new)
128132 } else {
129133 format ! (
130134 "{old} \u{2192}
131135{new}" ,
132- old = markdown_optional_commit( result. old. as_deref( ) ) ,
133- new = markdown_optional_commit( result. new. as_deref( ) ) ,
136+ old = markdown_optional_commit( result. old. as_deref( ) , github_info ) ,
137+ new = markdown_optional_commit( result. new. as_deref( ) , github_info ) ,
134138 )
135139 } ;
136140 format ! (
@@ -143,10 +147,33 @@ pub fn branch_check_message(
143147 )
144148}
145149
146- pub fn markdown_optional_commit ( commit : Option < & str > ) -> String {
150+ const SHORT_COMMIT_LENGTH : usize = 11 ;
151+
152+ pub fn short_commit ( commit : & str ) -> & str {
153+ & commit[ ..SHORT_COMMIT_LENGTH . min ( commit. len ( ) ) ]
154+ }
155+
156+ pub fn github_commit_diff ( github_info : & GitHubInfo , old : & str , new : & str ) -> String {
157+ let GitHubInfo { owner, repo, .. } = github_info;
158+ let old_short = short_commit ( old) ;
159+ let new_short = short_commit ( new) ;
160+ let url = format ! ( "https://github.com/{owner}/{repo}/compare/{old}...{new}" ) ;
161+ let text = format ! ( "{old_short}...{new_short}" ) ;
162+ markdown:: link ( & url, & markdown:: escape ( & text) )
163+ }
164+
165+ pub fn markdown_optional_commit ( commit : Option < & str > , github_info : Option < & GitHubInfo > ) -> String {
147166 match & commit {
148167 None => "\\ (nothing\\ )" . to_owned ( ) ,
149- Some ( c) => markdown:: code_inline ( & markdown:: escape ( c) ) ,
168+ Some ( commit) => match github_info {
169+ Some ( info) => {
170+ let GitHubInfo { owner, repo, .. } = info;
171+ let short = short_commit ( commit) ;
172+ let url = format ! ( "https://github.com/{owner}/{repo}/commit/{short}" ) ;
173+ markdown:: link ( & url, & markdown:: escape ( short) )
174+ }
175+ None => markdown:: code_inline ( & markdown:: escape ( commit) ) ,
176+ } ,
150177 }
151178}
152179
0 commit comments