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 |
# File 'lib/faure/agent.rb', line 13 def initialize payload = JSON.parse(ENV.fetch('TRIGGER_PAYLOAD', '{}')) @issue_iid = payload.dig('issue', 'iid').to_s end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 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 |
# File 'lib/faure/agent.rb', line 18 def run branch_name = "feature/issue-#{@issue_iid}" diff = `git diff origin/#{Config::TARGET_BRANCH}...#{branch_name} --stat` diff_full = `git diff origin/#{Config::TARGET_BRANCH}...#{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: " Voici le diff de la branche \#{branch_name} :\n \#{diff_full[0..3000]}\n R\u00E9dige une description de MR en 3-5 phrases : ce qui a \u00E9t\u00E9 fait, pourquoi, et ce qu'il faut v\u00E9rifier.\n PROMPT\n ])\n\n puts '[faure:agent] Description MR g\u00E9n\u00E9r\u00E9e'\n\n res = gitlab_post(\"/projects/\#{Config::PROJECT_ID}/merge_requests\", {\n source_branch: branch_name,\n target_branch: Config::TARGET_BRANCH,\n title: \"faure: r\u00E9solution issue #\#{@issue_iid}\",\n description: \"Closes #\#{@issue_iid}\\n\\n\#{description}\",\n reviewer_ids: [Config::REVIEWER_ID],\n remove_source_branch: true,\n squash: false\n })\n body = JSON.parse(res.body)\n\n if body['web_url']\n puts \"[faure:agent] MR cr\u00E9\u00E9e : \#{body['web_url']}\"\n else\n puts \"[faure:agent] Erreur cr\u00E9ation MR : \#{res.body}\"\n exit 1\n end\nend\n" } |