Class: Faure::Agent
- Inherits:
-
Object
- Object
- Faure::Agent
- Defined in:
- lib/faure/agent.rb
Instance Method Summary collapse
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/faure/agent.rb', line 13 def initialize raw = ENV.fetch('TRIGGER_PAYLOAD', '{}') raw = File.read(raw) if File.exist?(raw) payload = begin JSON.parse(raw) rescue JSON::ParserError => e abort "[faure] TRIGGER_PAYLOAD invalide : #{e.}" end @issue_iid = payload.dig('issue', 'iid').to_s end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/faure/agent.rb', line 24 def run branch_name = "feature/issue-#{@issue_iid}" system("git fetch origin #{branch_name} #{Config::TARGET_BRANCH}") diff = `git diff origin/#{Config::TARGET_BRANCH}...origin/#{branch_name} --stat` diff_full = `git diff origin/#{Config::TARGET_BRANCH}...origin/#{branch_name}` if diff.strip.empty? puts '[faure:agent] Aucun diff détecté, abandon.' exit 0 end puts "[faure:agent] Diff détecté :\n#{diff}" description = call_model([ { role: 'system', content: mr_system_prompt }, { role: 'user', content: <<~PROMPT } Voici le diff de la branche #{branch_name} : #{diff_full[0..3000]} Rédige une description de MR en 3-5 phrases : ce qui a été fait, pourquoi, et ce qu'il faut vérifier. PROMPT ]) puts '[faure:agent] Description MR générée' res = gitlab_post("/projects/#{Config::PROJECT_ID}/merge_requests", { source_branch: branch_name, target_branch: Config::TARGET_BRANCH, title: "faure: résolution issue ##{@issue_iid}", description: "Closes ##{@issue_iid}\n\n#{description}", reviewer_ids: [Config::REVIEWER_ID], remove_source_branch: true, squash: false }) body = JSON.parse(res.body) if body['web_url'] puts "[faure:agent] MR créée : #{body['web_url']}" else puts "[faure:agent] Erreur création MR : #{res.body}" exit 1 end end |