@@ -555,7 +555,6 @@ fn find_matching_revs(
555555}
556556
557557pub fn find_head ( ) -> Result < String > {
558- // If GITHUB_EVENT_PATH is set, try to extract PR head SHA from the event payload
559558 if let Ok ( event_path) = std:: env:: var ( "GITHUB_EVENT_PATH" ) {
560559 if let Ok ( content) = std:: fs:: read_to_string ( & event_path) {
561560 if let Some ( pr_head_sha) = extract_pr_head_sha_from_event ( & content) {
@@ -576,7 +575,6 @@ pub fn find_head() -> Result<String> {
576575/// Extracts the PR head SHA from GitHub Actions event payload JSON.
577576/// Returns None if not a PR event or if SHA cannot be extracted.
578577fn extract_pr_head_sha_from_event ( json_content : & str ) -> Option < String > {
579- // Parse the JSON payload using serde_json for robust parsing
580578 let payload: GitHubEventPayload = match serde_json:: from_str ( json_content) {
581579 Ok ( payload) => payload,
582580 Err ( _) => {
@@ -585,7 +583,6 @@ fn extract_pr_head_sha_from_event(json_content: &str) -> Option<String> {
585583 }
586584 } ;
587585
588- // Extract the PR head SHA if present
589586 Some ( payload. pull_request ?. head . sha )
590587}
591588
@@ -1517,7 +1514,6 @@ mod tests {
15171514
15181515 #[ test]
15191516 fn test_extract_pr_head_sha_from_event ( ) {
1520- // Test valid PR event JSON with valid 40-character SHA
15211517 let pr_json = r#"{
15221518 "action": "opened",
15231519 "number": 123,
@@ -1539,7 +1535,6 @@ mod tests {
15391535 Some ( "19ef6adc4dbddf733db6e833e1f96fb056b6dba5" . to_owned( ) )
15401536 ) ;
15411537
1542- // Test non-PR event
15431538 let push_json = r#"{
15441539 "action": "push",
15451540 "ref": "refs/heads/main",
@@ -1549,8 +1544,6 @@ mod tests {
15491544}"# ;
15501545
15511546 assert_eq ! ( extract_pr_head_sha_from_event( push_json) , None ) ;
1552-
1553- // Test malformed JSON (missing head SHA)
15541547 let malformed_json = r#"{
15551548 "pull_request": {
15561549 "id": 789,
@@ -1562,10 +1555,7 @@ mod tests {
15621555
15631556 assert_eq ! ( extract_pr_head_sha_from_event( malformed_json) , None ) ;
15641557
1565- // Test empty JSON
15661558 assert_eq ! ( extract_pr_head_sha_from_event( "{}" ) , None ) ;
1567-
1568- // Test real GitHub Actions PR event format (simplified)
15691559 let real_gh_json = r#"{
15701560 "action": "synchronize",
15711561 "pull_request": {
@@ -1587,8 +1577,6 @@ mod tests {
15871577 extract_pr_head_sha_from_event( real_gh_json) ,
15881578 Some ( "19ef6adc4dbddf733db6e833e1f96fb056b6dba4" . to_owned( ) )
15891579 ) ;
1590-
1591- // Test that user-controlled content with malicious patterns doesn't affect parsing
15921580 let malicious_json = r#"{
15931581 "action": "opened",
15941582 "pull_request": {
@@ -1605,8 +1593,6 @@ mod tests {
16051593 extract_pr_head_sha_from_event( malicious_json) ,
16061594 Some ( "19ef6adc4dbddf733db6e833e1f96fb056b6dba5" . to_owned( ) )
16071595 ) ;
1608-
1609- // Test that any SHA format is accepted (backend will validate)
16101596 let any_sha_json = r#"{
16111597 "pull_request": {
16121598 "head": {
@@ -1620,7 +1606,6 @@ mod tests {
16201606 Some ( "invalid-sha-123" . to_owned( ) )
16211607 ) ;
16221608
1623- // Test invalid JSON is handled gracefully
16241609 assert_eq ! ( extract_pr_head_sha_from_event( "invalid json {" ) , None ) ;
16251610 }
16261611
@@ -1630,8 +1615,6 @@ mod tests {
16301615
16311616 let temp_dir = tempdir ( ) . expect ( "Failed to create temp dir" ) ;
16321617 let event_file = temp_dir. path ( ) . join ( "event.json" ) ;
1633-
1634- // Test with valid PR event
16351618 let pr_json = r#"{
16361619 "action": "opened",
16371620 "pull_request": {
@@ -1643,13 +1626,8 @@ mod tests {
16431626
16441627 fs:: write ( & event_file, pr_json) . expect ( "Failed to write event file" ) ;
16451628
1646- // Set GITHUB_EVENT_PATH and test find_head
16471629 std:: env:: set_var ( "GITHUB_EVENT_PATH" , event_file. to_str ( ) . unwrap ( ) ) ;
1648-
1649- // Since we're not in a git repo, this would normally fail
1650- // But with GITHUB_EVENT_PATH set, it should return the PR head SHA
16511630 let result = find_head ( ) ;
1652-
16531631 std:: env:: remove_var ( "GITHUB_EVENT_PATH" ) ;
16541632
16551633 assert ! ( result. is_ok( ) ) ;
0 commit comments