GithubHelp home page GithubHelp logo

n7mobile / concourse-bitbucket-pr Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 3.0 95 KB

Interact with pull request on BitBucket Cloud with ConcourseCI.

License: MIT License

Dockerfile 0.95% Makefile 1.09% Go 95.93% Shell 2.03%
concourse bitbucket pullrequest concourse-resource

concourse-bitbucket-pr's Introduction

concourse-bitbucket-pr

Resource for ConcourseCI pipelines. Provides simple management of PullRequests:

  • Get list of opened PullRequests on BitBucket Cloud
  • Checkout repository at commit referenced by PullRequest
  • Set status for processed PullRequest on BitBucket Cloud

Docker image is hosted on dockerhub n7docker/concourse-bitbucket-pr.

Why?

There is a plenty of the ready-to-use projects doing same thing and even more (just search).

Unfortunately, using some of them, we hit a limitation of the number of API calls to BitBucket service (1000 requests per hour). As this limit is not so low, just watching for new PRs and set status for them should not exceed this value. But it was. The problem was calling /commits endpoint in order to fetch full SHA1 of updated commit instead of getting just current HEAD of cloned repository.

Instead of making a fix and PR to one of the existing project, we decided to create resource - absolutely simple, manageable and tailored to our case, which does not break the whole CI for our 20+ projects.

Who?

Resource is actively maintained by N7Mobile sp. z o.o.. We love OpenSource as it's free in many meanings.

Source Configuration

  • workspace: Required. Name of BitBucket organization/team.

  • slug: Required. Name of BitBucket repository.

  • username: Required. Username of BitBucket account with access to repository. Provided account is used for git clone (HTTPS) and BitBucket REST API.

  • password: Required. User password or user app password (in case of 2FA).

  • debug: Optional. Default false. Prints additional logs during processing.

  • recurse_submodules: Optional. Default false. Checkouts all submodules, if repo has any. Credentails are taken from the configuration of parent repo.

Example

Example files are placed in the examples directory, unexpectedly.

resource_types:
  - name: bitbucket-pr
    type: registry-image
    source:
      repository: n7docker/concourse-bitbucket-pr

resources:
  - name: pull-request
    type: bitbucket-pr
    check_every: 1m
    source:
      workspace: n7mobile
      slug: pr-test-repo
      username: ((ci_user))
      password: ((ci_pass))
      debug: true

jobs:
  - name: foo
    plan:
      - get: pull-request
        trigger: true
        version: every
      - put: pull-request
        params:
          repo_path: pull-request
          action: set:commit.build.status
          status: INPROGRESS
          url: example.com
          name: PR resource test
          description: Some userful description

Behavior

check: List of open PullRequests

List of the all open PullRequests for a given repository is fetched by BitBucket API v2. Paging is handled.

In order to retrieve full SHA1 of the last PR commit, bare checkout of a git is performed. It's minimalizes usage of the BitBucket API.

Version object is generated as:

{
    "ref": "", /* Full SHA1 of the commit */
    "id": ""   /* Identifier of Pullrequest */
}

in: Checkout by commit hash

Generally, git clone && git checkout 757c47d4 performed by libgit2.

Version object passed by Concourse is stored as .concourse.version.json and available to use by out step.

out: Set build status

Set a build status on the commit. Particular commit is identified by the hash in pull request.

Parameters

  • repo_path: Required. Name of the previous get: concourse-bitbucket-pr step where checked-out repo may be found.

  • action: Optional. Default set:commit.build.status. Identifier of the action to perform on PR. Currently, only set:commit.build.status is supported.

  • key: Optional. Default BUILD. Key of the commit build status. Passing multiple build statuses identified by a single key will overwrite each other. In case of the multiple builds from single commit (i.e. flutter -> iOS + Android), identifier of the current build iOS-$BUILD_NAME and Android-$BUILD_NAME should be passed.

  • status: Required. Commit build status to set. Possible values: STOPPED, INPROGRESS, FAILED, SUCCESSFUL

  • url: Required. URL to build status and results, ie. https://ci.example.com/builds/$BUILD_ID

  • name: Optional. Default $BUILD_JOB_NAME #$BUILD_ID. Name of the build status entity.

  • description: Optional. Default Concourse Build CI. Description of the build status entity.

Development

Prerequisites

  • golang is required - version 1.15.x or higher is required.
  • docker is required - version 17.05.x or higher is required.
  • make is required - version 4.1 of GNU make is tested.
  • libgit2 is required - version 1.1.0 is tested.

Operating

All task are defined in the self explanatory Makefile.

License

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

concourse-bitbucket-pr's People

Contributors

antrov avatar handrzejewski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

concourse-bitbucket-pr's Issues

PR Comment

Is there anyway to send back a comment to the Pull-Request?

Put error

When attempting to set the build status, I get this error. However, I am not able to find "resource/model: version path or name is empty" in the code. There are other "resource/model:" errors, but not the one displayed below. Is there a change that has not been tracked in git, but is in the docker image?

running command: %!w(*fmt.wrapError=&{resource/out: params invalid: resource/model: version path or name is empty 0xc00007ade0})

[Question] Build not triggered when additional commits arrive in Pull Request

Hi. I've set up pipeline with PR resource in its simplest form. It checks BitBucket repo every 2 minutes. When new PR arrives, Concourse build is triggered as expected and completes successfully.
Some time later I push additional commits to existing PR and expect it to trigger build again, but it does not happen.
Question: is it possible to trigger build again for newer commits? Thanks.

resource put failed

The example of the pipeline being used:

resource_types:
 - name: bitbucket-pr
   type: registry-image
   source:
     repository: n7mobile/concourse-bitbucket-pr

resources:
 - name: pull-request
   type: bitbucket-pr
   check_every: 1m
   source:
      workspace: ((bitbucket_project))
      slug: ((bitbucket_repo))
      username: ((bitbucket-username))
      password: ((bitbucket-password))
      debug: true

jobs:
  - name: check-pr
    serial: true
    plan:
    - get: pull-request
      version: every
      trigger: true
    - put: pull-request
      params:
         repo_path: pull-request
         action: set:commit.build.status
         status: INPROGRESS
         url: example.com

Resource put fails with the following error:

selected worker: concourse-worker-5995d5548d-gpv7f
calling out cmd wioth dest  /tmp/build/put
running command: %!w(*fmt.wrapError=&{resource/out: params invalid: resource/model: version path or name is empty 0xc00001c190})

OAuth 2.0 support

Hi there @antrov, at some point Bitbucket Cloud added support for OAuth 2.0 to their API.

It would be nice if this resource provided an option that allows users to take advantage of this.

In my use case, I have an OAuth Consumer in Bitbucket Cloud set up for Concourse and I would like to use those credentials with this resource rather than a username and password.

Is this something you would consider merging in if I can find the time to send you a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.