|
49 | 49 | let(:repo) { "discourse/discourse-automation" } |
50 | 50 | let(:pull_id) { 253 } |
51 | 51 | let(:diff) { <<~DIFF } |
52 | | - diff --git a/lib/discourse_automation/automation.rb b/lib/discourse_automation/automation.rb |
53 | | - index 3e3e3e3..4f4f4f4 100644 |
54 | | - --- a/lib/discourse_automation/automation.rb |
55 | | - +++ b/lib/discourse_automation/automation.rb |
56 | | - @@ -1,3 +1,3 @@ |
57 | | - -module DiscourseAutomation |
58 | | - DIFF |
| 52 | + diff --git a/lib/discourse_automation/automation.rb b/lib/discourse_automation/automation.rb |
| 53 | + index 3e3e3e3..4f4f4f4 100644 |
| 54 | + --- a/lib/discourse_automation/automation.rb |
| 55 | + +++ b/lib/discourse_automation/automation.rb |
| 56 | + @@ -1,3 +1,3 @@ |
| 57 | + -module DiscourseAutomation |
| 58 | + DIFF |
| 59 | + |
| 60 | + let(:pr_info) do |
| 61 | + { |
| 62 | + "title" => "Test PR", |
| 63 | + "state" => "open", |
| 64 | + "user" => { |
| 65 | + "login" => "test-user", |
| 66 | + }, |
| 67 | + "created_at" => "2023-01-01T00:00:00Z", |
| 68 | + "updated_at" => "2023-01-02T00:00:00Z", |
| 69 | + "head" => { |
| 70 | + "repo" => { |
| 71 | + "full_name" => "test/repo", |
| 72 | + }, |
| 73 | + "ref" => "feature-branch", |
| 74 | + "sha" => "abc123", |
| 75 | + }, |
| 76 | + "base" => { |
| 77 | + "repo" => { |
| 78 | + "full_name" => "main/repo", |
| 79 | + }, |
| 80 | + "ref" => "main", |
| 81 | + }, |
| 82 | + } |
| 83 | + end |
| 84 | + |
| 85 | + it "retrieves both PR info and diff" do |
| 86 | + stub_request(:get, "https://api.github.com/repos/#{repo}/pulls/#{pull_id}").with( |
| 87 | + headers: { |
| 88 | + "Accept" => "application/json", |
| 89 | + "User-Agent" => DiscourseAi::AiBot::USER_AGENT, |
| 90 | + }, |
| 91 | + ).to_return(status: 200, body: pr_info.to_json) |
59 | 92 |
|
60 | | - it "retrieves the diff for the pull request" do |
61 | 93 | stub_request(:get, "https://api.github.com/repos/#{repo}/pulls/#{pull_id}").with( |
62 | 94 | headers: { |
63 | 95 | "Accept" => "application/vnd.github.v3.diff", |
|
67 | 99 |
|
68 | 100 | result = tool.invoke |
69 | 101 | expect(result[:diff]).to eq(diff) |
| 102 | + expect(result[:pr_info]).to include(title: "Test PR", state: "open", author: "test-user") |
70 | 103 | expect(result[:error]).to be_nil |
71 | 104 | end |
72 | 105 |
|
73 | 106 | it "uses the github access token if present" do |
74 | 107 | SiteSetting.ai_bot_github_access_token = "ABC" |
75 | 108 |
|
| 109 | + stub_request(:get, "https://api.github.com/repos/#{repo}/pulls/#{pull_id}").with( |
| 110 | + headers: { |
| 111 | + "Accept" => "application/json", |
| 112 | + "User-Agent" => DiscourseAi::AiBot::USER_AGENT, |
| 113 | + "Authorization" => "Bearer ABC", |
| 114 | + }, |
| 115 | + ).to_return(status: 200, body: pr_info.to_json) |
| 116 | + |
76 | 117 | stub_request(:get, "https://api.github.com/repos/#{repo}/pulls/#{pull_id}").with( |
77 | 118 | headers: { |
78 | 119 | "Accept" => "application/vnd.github.v3.diff", |
|
94 | 135 | it "returns an error message" do |
95 | 136 | stub_request(:get, "https://api.github.com/repos/#{repo}/pulls/#{pull_id}").with( |
96 | 137 | headers: { |
97 | | - "Accept" => "application/vnd.github.v3.diff", |
| 138 | + "Accept" => "application/json", |
98 | 139 | "User-Agent" => DiscourseAi::AiBot::USER_AGENT, |
99 | 140 | }, |
100 | 141 | ).to_return(status: 404) |
101 | 142 |
|
102 | 143 | result = tool.invoke |
103 | 144 | expect(result[:diff]).to be_nil |
104 | | - expect(result[:error]).to include("Failed to retrieve the diff") |
| 145 | + expect(result[:error]).to include("Failed to retrieve the PR information") |
105 | 146 | end |
106 | 147 | end |
107 | 148 | end |
0 commit comments