gpt4 book ai didi

xcode - 手动启动Xcode Bot集成吗?

转载 作者:行者123 更新时间:2023-12-04 16:59:58 25 4
gpt4 key购买 nike

我在看WWDC 2014“与Xcode的持续集成”视频,看起来如何使用机器人进行测试看起来很棒。
但是我的问题是,当他向Jeeves发送消息“集成CoffeeBoard”时,看到该视频的任何人。Bot开始集成。我想知道他是怎么做到的。

我想在github上添加post-receive钩子,该钩子在接收到任何提交后应在OS X Server上启动Xcode bot。我的大多数团队成员都使用SourceTree或GitHub来管理他们的git,并且他们不想使用Xcode Source Control。我认为创建一个机器人并将其选项设置为手动启动就可以解决问题。我需要知道,“ OS X Server是否为您提供了诸如会启动bot的url之类的选项?”

抱歉,如果我不够清楚。但这对我来说太混乱了,因为他们关于触发器的文档很少。尽管他提到这是很酷的新功能,但他们没有提供任何信息来实现这一目标

最佳答案

前两个答案并不能完全回答最初的问题“他们是如何做到的”,以便从Messages应用程序中启动机器人。

我已经重新创建了模仿Jeeves虚拟助手与机器人进行交互(并获取天气)所需的确切工作流程和脚本。

有关完整的详细信息,请参见链接的PDF文档:

https://s3.amazonaws.com/icefield/IntegratingXcodeBotsWithMessages.pdf

编辑:原始答案被删除,我相信是由于我通过完整答案的链接引用了这一事实。此编辑将完整的实施详细信息添加为此答案的一部分。我希望不久就可以得到一个答案。

将Xcode Bot与消息集成

在WWDC 2014 Session 415(与Xcode 6持续集成)中,Apple演示了通过自定义集成触发器将Xcode bot与Messages应用程序集成。更具体地说,从该会话视频(https://developer.apple.com/videos/play/wwdc2014-415/)的23分钟开始,Apple演示了结合使用集成触发器和Messages来接收构建服务器上的集成状态。此外,通过使用虚拟聊天室成员Jeeves,他们展示了直接从Messages应用程序中开始集成的能力。下面的文章提供了重现该功能的分步说明。

客户端和服务器配置

首先,这是我用来模仿Jeeves功能的客户端和服务器的配置:

客户
OS X版本10.11(El Capitan),Xcode 7.0.1

服务器
OS X版本10.11(El Capitan),OS X Server 5.0.4,Xcode 7.0.1,Ruby 2.0.0p645

网络
为了进行开发和持续集成,我使用内部网络。我的OS X Server位于domain.local,而我的开发机器是同一内部网络上的另一个节点。无论您使用内部还是外部服务器,以下说明均应适用。

Jabber –消息的基础

Jabber是用于实例消息传递的开源协议的原始名称。 Jabber被重命名为可扩展消息和状态协议(XMPP)。 OS X Messages应用是使用Jabber为其核心构建的。

为此,我们将广泛使用Jabber(消息),因此请确保它已打开。在OS X Server App中,选择“服务”>“消息”视图,然后在右上角打开“消息”。对于Jeeves,我使用的Messages服务设置如下:

Messages service settings

在服务器的终端窗口中,如果要检查Jabber的特定设置,请使用

$ sudo serveradmin settings jabber


特别注意jabberClientPortTLS(5222)和jabberClientPortSSL(5223)值。这些是服务器上用于与Jabber服务进行通信的端口。

我们将使用Ruby编写Jeeves的大多数脚本,并且需要一个XMPP / Jabber库来完成此任务。在服务器的终端窗口中,使用以下命令安装XMPP4R(Ruby的XMPP / Jabber库)

$ gem install xmpp4r


为Jabber服务创建用户

因为我的服务器是本地服务器,上面没有任何开发人员帐户,所以我需要为各种开发人员创建帐户以登录到Jabber。您可能需要也可能不需要此步骤,具体取决于您的服务器是否已经定义了用户帐户。

从服务器上的OS X Server App中,转到“帐户”>“用户”列表,然后为将使用虚拟Jeeves助手的每个客户端添加新用户。确保为Jeeves创建一个新用户。对于用户“ Tom”,这是使用的设置。确保为每个用户创建一个电子邮件地址,但是邮件服务不需要运行。这些电子邮件地址将用于从客户端上的Messages App登录到Jabber服务。

User settings

从客户端开发机登录到Jabber

使用服务器上定义的用户帐户,现在可以从客户端计算机登录Jabber帐户了。在客户端上的消息应用程序中,转到消息>首选项>帐户。选择左下方的+号,选择“其他邮件帐户...”,然后按继续。在“添加消息帐户”对话框中,为帐户类型选择“ Jabber”,然后为您的用户填写凭据信息。这是我使用的设置:

enter image description here

(请注意,如果启用了SSL,则端口(5223)与您在服务器上检查Jabber服务的设置时前面列出的jabberClientPortSSL值匹配。)

成功登录Jabber服务后,您可以选择在Jabber帐户的“聊天设置”页面下更改帐户昵称。其他所有默认设置都可以保留不变。

创建聊天室

我们希望所有bot集成状态以及与虚拟助手Jeeves的通信都可以通过Messages聊天室进行。聊天室可以进行群组交流,但您不需要邀请即可加入。要创建聊天室,请执行以下操作。

在消息中,选择文件>转到聊天室。您应该看到列出了登录到Jabber服务的帐户。输入Room @ name的Integration @ rooms..local,然后选择执行。 (请注意,我发现聊天室必须是“ rooms..local” .com”。使用“ rooms”以外的其他字词不会创建聊天室。)

Create chat room

配置服务器网站服务

从客户端计算机上运行的Xcode开始集成时,集成前和集成后脚本通过对OS X Server网站服务上的文件进行http调用来与Jabber服务进行通信。您必须配置OS X Server网站服务来处理这些调用。

您需要修改非SSL http(端口80)网站的设置。这是我使用的设置。

Web server settings

选择“ Port 80网站”,然后选择下方的铅笔图标以使您的设置符合这些要求。

Web server settings

选择“编辑高级设置...”并使您的设置与这些设置匹配。 (启用“允许CGI执行...”将启用Ruby脚本执行。)

Web server settings

最后,您需要启用一个特定的文件(message_room,我们将在后面讨论)被配置为以Ruby脚本的形式运行。为此,请将以下.htaccess文件放置在Web服务器的默认主文件夹(通常为/ Library / Server / Web / Data / Sites / Default)中。

Options +ExecCGI 
<FilesMatch message_room$>
SetHandler cgi-script
</FilesMatch>


注意:在以下所有的ruby脚本中,您需要修改每个脚本中“ credentials”注释下的变量,以匹配您的域和登录凭据。

集成前和集成后脚本
当我们从客户端计算机上的Xcode启动集成时,我们希望向Jabber集成聊天室发送消息,以便可以通知聊天室的所有成员集成已经开始(和完成)。在Xcode的bot触发器页面上,将以下集成前和集成后脚本添加到项目的bot中。

这是集成前触发器脚本:

#!/usr/bin/env ruby 
require 'json'
require 'net/http'
require 'uri'

# -------------------------------------------------------------------------------------
# credentials and such
domain = "<yourDomain>.local"

# -------------------------------------------------------------------------------------
# our messaging endpoint
uri = URI.parse("http://#{domain}:80/message_room")

# -------------------------------------------------------------------------------------
# what we want to say
message = "#{ENV['XCS_BOT_NAME']} integration #{ENV['XCS_INTEGRATION_NUMBER']} is now starting."

# -------------------------------------------------------------------------------------
# build up the request body
reqBody = {:message => message}
body = JSON.generate(reqBody)

# -------------------------------------------------------------------------------------
# the connect type
http = Net::HTTP.new(uri.host, uri.port)

# -------------------------------------------------------------------------------------
# build up the request
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-type', 'application/json')
request.body = body

# -------------------------------------------------------------------------------------
# send the request and get the response
response = http.request(request)


这是集成后的触发器脚本:

#!/usr/bin/env ruby 
require 'json'
require 'net/http'
require 'uri'

# -------------------------------------------------------------------------------------
# credentials and such
domain = "<yourDomain>.local"

# -------------------------------------------------------------------------------------
# our messaging endpoint
uri = URI.parse("http://#{domain}:80/message_room")

# -------------------------------------------------------------------------------------
# what we want to say
integrationResult = case ENV['XCS_INTEGRATION_RESULT']
when "succeeded"
"has completed successfully."
when "test-failures"
tc = ENV['XCS_TEST_FAILURE_COUNT'].to_i
"completed with #{tc} failing #{(tc ==1 ) ? 'test' : 'tests'}."
when "build-errors"
ec = ENV['XCS_ERROR_COUNT'].to_i
"failed with #{ec} build #{(ec == 1) ? 'error' : 'errors'}."
when "warnings"
wc = ENV['XCS_WARNING_COUNT'].to_i
"completed with #{wc} #{(wc == 1) ? 'warning' : 'warnings'}."
when "analyzer-warnings"
ic = ENV['XCS_ANALYZER_WARNING_COUNT'].to_i
"completed with #{ic} static analysis #{(ic == 1) ? 'issue' : 'issues'}."
when "trigger-error"
"failed running trigger script."
when "checkout-error"
"failed to checkout from source control."
else
"failed with unexpected errors."
end

message = "#{ENV['XCS_BOT_NAME']} integration #{ENV['XCS_INTEGRATION_NUMBER']} #{integrationResult}"

# -------------------------------------------------------------------------------------
# build up the request body
reqBody = {:message => message}
body = JSON.generate(reqBody)

# -------------------------------------------------------------------------------------
# the connect type
http = Net::HTTP.new(uri.host, uri.port)

# -------------------------------------------------------------------------------------
# build up the request
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-type', 'application/json')
request.body = body

# -------------------------------------------------------------------------------------
# send the request and get the response
response = http.request(request)


前两个Ruby脚本会调用OS X Server网站主文件夹(通常为/ Library / Server / Web / Data / Sites / Default)中的message_room文件。将以下message_room文件放入该文件夹。

#!/usr/bin/env ruby
require 'cgi'
require 'json'
require 'xmpp4r'
require 'xmpp4r/muc'

# -------------------------------------------------------------------------------------
# credentials and such
domain = "<domain>.local"
userId = "jeeves@#{domain}"
userPw = "<jeevesAccountPassword>"
roomName = "integration@rooms.#{domain}"

# -------------------------------------------------------------------------------------
# header sent back
cgi = CGI.new
puts cgi.header( "type" => "text/html", "status" => "OK")

# -------------------------------------------------------------------------------------
# get the message out of the json formatted text
keyValue = JSON.parse(cgi.params.keys.first)
key = "message"
value = keyValue[key] puts value

# -------------------------------------------------------------------------------------
# create the message to the iChat (jabber) room
fromJID = Jabber::JID.new(userId)
jabberClient = Jabber::Client.new(fromJID)
jabberClient.connect
jabberClient.auth(userPw)
jabberClient.send(Jabber::Presence.new.set_type(:available))

# -------------------------------------------------------------------------------------
# send the message to a chat room
roomID = roomName + "/" + jabberClient.jid.node
roomJID = Jabber::JID::new(roomID)
room = Jabber::MUC::MUCClient.new(jabberClient) room.join(roomJID)
roomMessage = Jabber::Message.new(roomJID, value) room.send(roomMessage)


从Messages App启动集成

我们希望能够从Messages App中向虚拟助手Jeeves发布指令。我们将支持以下三个说明:


吉夫斯,天气#获取当前天气(不包括
zip默认为Cupertino)
Jeeves,集成(Bot名称)#为给定的集成开始集成
机器人
Jeeves,退出#关闭OS X Server上的Jeeves


以下文件将放置在OS X Server网站的默认文件夹(通常为/ Library / Server / Web / Data / Sites / Default)中。

处理虚拟助手Jeeves的主要文件是jeevesManager.rb。通过输入以下内容启动该文件以唤醒Jeeves

$ ruby ./jeevesManager.rb


从服务器上网站的默认文件夹中访问。

#!/usr/bin/env ruby
require 'xmpp4r'
require 'xmpp4r/muc'
require 'xmpp4r/delay'
require './jeevesWeather.rb'
require './jeevesIntegration.rb'

# -------------------------------------------------------------------------------------
# credentials and such
domain = "<domain>.local"
userId = "jeeves@#{domain}"
userPw = "<jeevesAccountPassword>"
roomName = "integration@rooms.#{domain}"
defaultWeatherZipCode = "95015"

# -------------------------------------------------------------------------------------
# create the client we'll use
fromJID = Jabber::JID.new(userId)
jabberClient = Jabber::Client.new(fromJID)
jabberClient.connect
jabberClient.auth(userPw)
jabberClient.send(Jabber::Presence.new.set_type(:available))

# -------------------------------------------------------------------------------------
# connect to the chatroom
roomID = roomName + "/" + jabberClient.jid.node
roomJID = Jabber::JID::new(roomID)
room = Jabber::MUC::MUCClient.new(jabberClient) room.join(roomJID)

# -------------------------------------------------------------------------------------
# weather
def getWeather(m)
begin
words = m.body.downcase.split("weather")
where = defaultWeatherZipCode
if (words.length == 2)
where = words[1].strip
end
weather = get_weather_for_city(where,'f')
rescue
weather = "Couldn't get weather for that location - try zip code"
end
return weather
end

# -------------------------------------------------------------------------------------
# integration
def startIntegration(m)
begin
words = m.body.split("integrate")
botName = "Invalid BOT Name"
if (words.length == 2)
botName = words[1].strip
end
integrationMessage = jeevesIntegration(botName)
rescue
integrationMessage = "Failed integrating #{botName}"
end
return integrationMessage
end

# -------------------------------------------------------------------------------------
# listen for messages in chatroom (this callback will run in a separate thread)
room.add_message_callback do |m|
if (m.x.nil?) # the msg is current
if m.type != :error
body = m.body;
if (body.downcase.include? "jeeves")

# assume Jeeves does not understand command
understood = 0

# exit Jeeves
if (body.downcase.include? "exit")
understood = 1
message = "Good-bye"
mainthread.wakeup
end

# Weather
if (body.downcase.include? "weather")
understood = 1
message = getWeather(m)
end

# Integrate BOT
if (body.downcase.include? "integrate")
understood = 1
message = startIntegration(m)
end

# Jeeves doesn't understand command
if (understood == 0)
message = "I don't understand that command!"
end

# let user know what has happened
roomMessage = Jabber::Message.new(roomJID, message)
room.send(roomMessage)
end
end
end
end


# -------------------------------------------------------------------------------------
# add the callback to respond to server ping (to keep the connect alive)
jabberClient.add_iq_callback do |iq_received|
if iq_received.type == :get
if iq_received.queryns.to_s != 'http://jabber.org/protocol/disco#info'
iq = Jabber::Iq.new(:result, jabberClient.jid.node)
iq.id = iq_received.id
iq.from = iq_received.to
iq.to = iq_received.from
jabberClient.send(iq)
end
end
end

# -------------------------------------------------------------------------------------
# stop the main thread (the call back will still be alive this way)
print "Connected to chat room...\n"
Thread.stop
print "Disconnected from chat room...\n"

# leave chat room and log out of Jabber
room.exit
jabberClient.close


上面的Jeeves管理器文件还使用了另外两个补充文件。下面的第一个处理获取天气预报并将其格式化,第二个处理开始集成。

######### Weather #########
require 'rexml/document'
require 'open-uri'
require 'net/smtp'

# -------------------------------------------------------------------------------------
# yahoo weather url info
# http://developer.yahoo.net/weather/#examples

# -------------------------------------------------------------------------------------
#Returns a hash containing the location and temperature information
#Accepts US zip codes or Yahoo location id's
def yahoo_weather_query(loc_id, units)
h = {}
open("http://xml.weather.yahoo.com/forecastrss?p=#{loc_id}&u=#{units}") do |http|
response = http.read
doc = REXML::Document.new(response)
root = doc.root
channel = root.elements['channel']
location = channel.elements['yweather:location']
h[:city] = location.attributes["city"]
h[:region] = location.attributes["region"]
h[:country] = location.attributes["country"]
h[:temp] = channel.elements["item"].elements["yweather:condition"].attributes["temp"]
h[:text] = channel.elements["item"].elements["yweather:condition"].attributes["text"]
h[:wind_speed] = channel.elements['yweather:wind'].attributes['speed']
h[:humidity] = channel.elements['yweather:atmosphere'].attributes['humidity']
h[:sunrise] = channel.elements['yweather:astronomy'].attributes['sunrise']
h[:sunset] = channel.elements['yweather:astronomy'].attributes['sunset']
h[:forecast_low] = channel.elements["item"].elements['yweather:forecast'].attributes['low']
h[:forecast_high] = channel.elements["item"].elements['yweather:forecast'].attributes['high'] end
return h
end

# -------------------------------------------------------------------------------------
def get_weather_for_city(city_code,units)
weather_info = yahoo_weather_query(city_code, units)
city = weather_info[:city]
region = weather_info[:region]
country = weather_info[:country]
temp = weather_info[:temp]
wind_speed = weather_info[:wind_speed]
humidity = weather_info[:humidity]
text = weather_info[:text]
sunrise = weather_info[:sunrise]
sunset = weather_info[:sunset]
forecast_low = weather_info[:forecast_low]
forecast_high = weather_info[:forecast_high]

return "#{city}, #{region}:\n" + " Currently #{temp} degrees, #{humidity}% humidity, #{wind_speed} mph winds, #{text}.\n" + " Forecast: #{forecast_low} low, #{forecast_high} high.\n" + " Sunrise: #{sunrise}, sunset: #{sunset}.\n"
end


最后,这是启动Messages应用程序集成的脚本

require 'json' 
require 'open-uri'
require 'openssl'

# -------------------------------------------------------------------------------------
def jeevesIntegration(botToIntegrate)

# credentials
domain = "<domain>.local"
endpoint = "https://#{domain}:20343"
user = "your-integration-username (not Jeeves)"
password = "password"

# return message
message = "Bot '#{botToIntegrate}' does not exist on server #{domain}"

# request JSON construct with all the BOTS
botsRequestURI = URI.parse("#{endpoint}/api/bots")
output = open(botsRequestURI, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE})
bots = JSON.parse(output.readlines.join(""))

# loop through full list of BOTS for the one we're interested in
bots['results'].each do |bot|
botName = bot['name']
if (botName.downcase == botToIntegrate.downcase)
botID = bot['_id']

# curl -k -X POST -u "#{user}:#{password}" "#{endpoint}/api/bots/#{botid}/integrations" -i

# -------------------------------------------------------------------
# kickoff integration
uri = URI.parse(endpoint)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/api/bots/#{botID}/integrations")
request.basic_auth(user, password)
response = http.request(request)
message = "Integrating #{botName} on server #{domain}"
end
end

return message
end

关于xcode - 手动启动Xcode Bot集成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28365091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com