通过名称链接到GitHub里程碑

时间:2019-06-25 07:04:21

标签: github milestone

我想按名称链接到GitHub里程碑。我们有由版本号命名的里程碑,例如$(document).ready(function() { var final_total_amt = $('#final_total_amt').text(); var count = 1; $(document).on('click', '#add_row', function() { count++; $('#total_item').val(count); var html_code = ''; html_code += '<tr id="row_id_' + count + '">'; html_code += '<td><span id="sr_no">' + count + '</span></td>'; html_code += '<td><textarea name="vendor[]" id="vendor' + count + '" rows = "5" cols = "20" data-srno="' + count + '" class= "form-control input-sm" ></textarea></td>'; html_code += '<td><textarea name="itemdescription[]" id="itemdescription' + count + '" rows = "5" cols = "20" data-srno="' + count + '" class= "form-control input-sm" ></textarea></td>'; html_code += '<td><input type= "text" id="order_item_quantity' + count + '" name="order_item_quantity[]" data-srno="' + count + '" class= "form-control input-sm number_only order_item_quantity"></td>'; html_code += '<td><input type= "text" id="order_item_price' + count + '" name="order_item_price[]" data-srno="' + count + '" class= "form-control input-sm order_item_price"></td>'; html_code += '<td><input type= "text" id = "order_item_final_amount'+count+'" name = "order_item_final_amount[]" data - srno = "'+count+'" class = "form-control input-sm order_item_final_amount " readonly > < /td>'; html_code += '<td></td>'; html_code += '<td><button type="button" name="remove_row" id = "'+count+'" class = "btn btn-danger btn-xs remove_row" > X < /button> < /td>'; html_code += '</tr>'; $('#invoice-item-table').append(html_code); }); $(document).on('click', '.remove_row', function() { var row_id = $(this).attr("id"); var total_item_amount = $('#order_item_final_amount' + row_id).val(); var final_amount = $('#final_total_amt').text(); var result_amount = parseFloat(final_amount) - parseFloat(total_item_amount); $('#final_total_amt').text(result_amount); $('#totcost').text(result_amount); $('#row_id_' + row_id).remove(); $('#poloam1').text(poloam); count--; $('#total_item').val(count); }); function cal_final_total(count) { var final_item_total = 0; var grossprofit = 0; var grossprofitpercen = 0; for (j = 1; j <= count; j++) { var quantity = 0; var price = 0; var actual_amount = 0; var item_total = 0; quantity = $('#order_item_quantity' + j).val(); if (quantity >= 0) { price = $('#order_item_price' + j).val(); if (price >= 0) { actual_amount = parseFloat(quantity) * parseFloat(price); item_total = parseFloat(actual_amount); final_item_total = parseFloat(final_item_total) + parseFloat(item_total); $('#order_item_final_amount' + j).val(item_total); } } } $('#final_total_amt').val(final_item_total); polo = $('#poloam1').val(); grossprofit = parseFloat(polo) - parseFloat(final_item_total); $('#grossprofit').val(grossprofit); $('#poloamount').text(polo); $('#totcost').text(final_item_total); grossprofitpercen = parseFloat(grossprofit) / (parseFloat(final_item_total) / 100); $('#grossprofitpercen').val(grossprofitpercen.toFixed(2)); } $(document).on('blur', '.order_item_price', function() { cal_final_total(count); }); $(document).on('blur', '.grossprofit', function() { cal_final_total(count); }); $(document).on('blur', '.grossprofitpercen', function() { cal_final_total(count); }); $(document).on('blur', '.final_total_amt', function() { cal_final_total(count); }); }); 0.1.00.1.1 ...,但里程碑URL具有内部编号(https://github.com/owner/project/milestone/1https://github.com/owner/project/milestone/2,...)。仅给出里程碑名称,如何自动生成指向相应里程碑URL的链接?

1 个答案:

答案 0 :(得分:0)

似乎没有官方方法或第三方服务以其名称链接到GitHub里程碑,但是基于GitHub API构建此类服务很容易。如jonrsharpe所示,milestones API可用于查询所有里程碑,然后找到相应的链接。在给定用户$USER,存储库名称$REPO和里程碑名称$VERSION的情况下,这一行获取里程碑URL(需要curljq):

curl -s 'https://api.github.com/repos/$USER/$REPO/milestones?per_page=100' \
  | jq -r ".[]|select(.title==\"$VERSION\").html_url"

由于API响应分页,此方法最多只能使用100个里程碑。