ruby用于检查codeship状态的简单ruby脚本(代码片段)

author author     2023-01-14     716

关键词:

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

# Replace YOUR_API_KEY with your Codeship API key
API_KEY = 'YOUR_API_KEY'

# Change this to ['repository/name', 'repository/name2'] if you want to filter only specific projects
PROJECTS = nil 

# If you want to keep the status file in someplace else (like ~/ directory), change this,
# otherwise just leave it as is
STATUS_FILE = File.join(File.dirname(__FILE__), '.codeship_status')

def projects
  response = Net::HTTP.get(URI("https://codeship.com/api/v1/projects.json?api_key=#API_KEY"))
  projects = JSON.parse(response)

  if projects.has_key?('error')
    raise projects['error']
  else 
    PROJECTS.nil? ? projects : projects.select  |project| PROJECTS.include?(project['repository_name']) 
  end
end

def builds
  projects.map do |project| 
    build = project['builds'][0]
    build['project_name'] = project['repository_name'].split('/')[1..-1].join('/') 
    build 
  end
end

def message(message, wait_time)
  json =  "message" => message, "updateAt" => Time.now + wait_time 
  File.write(STATUS_FILE, json.to_json)

  puts message
end

current = File.exists?(STATUS_FILE) ? JSON.parse(File.read(STATUS_FILE)) :  "updateAt" => Time.now.to_s 

if Time.now > Time.parse(current['updateAt'])
  build = builds.find  |build| build['status'] != 'success' 

  if build.nil?
    message "All builds have passed successfully.", 60
  elsif build['status'] == 'error'
    message "Build failed for #build['project_name'].", 60
  else
    message "Build in progress...", 5
  end
else
  puts current['message']
end

用于检查应用程序中有多少行代码的 Ruby 脚本

】用于检查应用程序中有多少行代码的Ruby脚本【英文标题】:Rubyscripttocheckhowmanylinesofcodeareinanapplication【发布时间】:2011-09-2604:31:53【问题描述】:您将如何编写诸如get_lines.rbfile_name.rb之类的ruby​​脚本,它返回通过文件夹>... 查看详情

ruby这个片段是一种简单的ruby方式,用于计算在twitter上共享指定网址的次数。(代码片段)

查看详情

Ruby:检查数组的唯一值并返回最小距离(haversine 公式)

...】:很难理解这一点。我有两个组成光纤网络的CSV:一个用于纬度,一个用于经度。这些是从KMZ文件中提取的,由于KMZ构建不佳,两个CS 查看详情

ruby用于检查rails_admin实现中的自定义操作的集成测试(代码片段)

查看详情

是否有一种简单的方法来检查 Ruby IO 实例是否会在 read() 上阻塞?

】是否有一种简单的方法来检查RubyIO实例是否会在read()上阻塞?【英文标题】:IsthereasimplemethodforcheckingwhetheraRubyIOinstancewillblockonread()?【发布时间】:2010-10-3004:20:52【问题描述】:我正在寻找一种Ruby中的方法,基本上是这样的:... 查看详情

如何检查特定属性是不是是有效的 ruby​​ on rails

】如何检查特定属性是不是是有效的ruby​​onrails【英文标题】:Howtocheckifaspecificattributeisvalidrubyonrails如何检查特定属性是否是有效的ruby​​onrails【发布时间】:2022-01-2010:58:06【问题描述】:我一直在寻找一种开箱即用的方法... 查看详情

Ruby v2 的 aws-sdk:在我将对象放入 S3 存储桶后检查成功状态

】Rubyv2的aws-sdk:在我将对象放入S3存储桶后检查成功状态【英文标题】:aws-sdkforRubyv2:checksuccessstatusafterIPUTobjectinS3bucket【发布时间】:2017-03-0112:19:08【问题描述】:我正在使用适用于Ruby的aws-sdkv2,我发现对象上可用的方法非常... 查看详情

ruby用于理解ruby块的代码。(代码片段)

查看详情

ruby用于创建封装json序列化逻辑的类的简单模式。只需继承`baseserializer`并覆盖h(代码片段)

查看详情

如何检查变量是不是是 Ruby 中的日期或时间或日期时间?

】如何检查变量是不是是Ruby中的日期或时间或日期时间?【英文标题】:HowtocheckifvariableisDateorTimeorDateTimeinRuby?如何检查变量是否是Ruby中的日期或时间或日期时间?【发布时间】:2016-10-2421:47:55【问题描述】:有什么简单的方法... 查看详情

ruby用于测试博客帖子的ruby代码。(代码片段)

查看详情

ruby用于循环尝试次数的ruby方法(代码片段)

查看详情

ruby类,用于简单的版本号自然顺序排序

Probablynotthemostelegantsolution,butitworks.Neededthisforacapistranodeploytaskwhichshowsthemostrecenttaggedreleasesinmyrepository.Verybarebones,andneedstweakingifyourversionsarenotinX.X.X.Xformat.classVersionincludeComparable attr_reader:major,:feature_group,:feature,:bugfix definitialize... 查看详情

ruby简单的ruby内存基准(代码片段)

查看详情

ruby简单的ruby内存基准(代码片段)

查看详情

ruby用于urlshortner的编码/解码函数-在ruby中(代码片段)

查看详情

无法使用 graphql-ruby 订阅进行简单广播

...】:2021-01-1915:39:36【问题描述】:我有一个准系统设置,用于通过ActionCable使用graphql-ruby进行更新广播。客户端在订阅时收到初始有效负载。客户端没有收到任何更新并且订阅类型的update方法没有被调用。后 查看详情

ruby使用nokogiri的简单ruby刮刀(代码片段)

查看详情