Skip to content

Commit

Permalink
Merge pull request #11 from turbot/release/v0.2
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
bigdatasourav authored Feb 8, 2024
2 parents 833c9d6 + 0175fa9 commit 88994a3
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## v0.2.0 [2024-02-08]

_What's new?_

- Added `create_branch`, `delete_branch` and `get_branch` pipelines. ([#10](https://github.com/turbot/flowpipe-mod-github/pull/10))

## v0.1.0 [2023-12-13]

_What's new?_

- Added 35+ pipelines to make it easy to connect your issues, pull requests, repositories and more. For usage information and a full list of pipelines, please see [GitHub Mod for Flowpipe](https://hub.flowpipe.io/mods/turbot/github).
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ GitHub pipeline library for [Flowpipe](https://flowpipe.io), enabling seamless i

## Getting Started

### Requirements

Docker daemon must be installed and running. Please see [Install Docker Engine](https://docs.docker.com/engine/install/) for more information.

### Installation

Download and install Flowpipe (https://flowpipe.io/downloads). Or use Brew:
Expand Down
63 changes: 63 additions & 0 deletions pipelines/branch/create_branch.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pipeline "create_branch" {
title = "Create Branch"
description = "Creates a new branch in a specified repository."

param "cred" {
type = string
default = "default"
description = local.cred_param_description
}

param "repository_owner" {
type = string
description = local.repository_owner_param_description
}

param "repository_name" {
type = string
description = local.repository_name_param_description
}

param "branch_name" {
type = string
description = "The name of the new branch."
}

param "source_branch" {
type = string
description = "The name of the source branch to branch off. Defaults to the default branch of the repository."
default = "main"
}

step "http" "get_latest_commit_sha" {
method = "get"
url = "https://api.github.com/repos/${param.repository_owner}/${param.repository_name}/branches/${param.source_branch}"
request_headers = {
Authorization = "Bearer ${credential.github[param.cred].token}"
}
}

step "http" "create_branch" {
method = "post"
url = "https://api.github.com/repos/${param.repository_owner}/${param.repository_name}/git/refs"
request_headers = {
Content-Type = "application/json"
Authorization = "Bearer ${credential.github[param.cred].token}"
}

request_body = jsonencode({
ref = "refs/heads/${param.branch_name}",
sha = "${step.http.get_latest_commit_sha.response_body.commit.sha}"
})

throw {
if = can(result.response_body.errors)
message = join(", ", flatten([for error in result.response_body.errors : error.message]))
}
}

output "branch" {
value = step.http.create_branch
}

}
43 changes: 43 additions & 0 deletions pipelines/branch/delete_branch.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pipeline "delete_branch" {
title = "Delete Branch"
description = "Deletes a branch in a specified repository."

param "cred" {
type = string
default = "default"
description = local.cred_param_description
}

param "repository_owner" {
type = string
description = local.repository_owner_param_description
}

param "repository_name" {
type = string
description = local.repository_name_param_description
}

param "branch_name" {
type = string
description = "The name of the branch to delete."
}

step "http" "delete_branch" {
method = "delete"
url = "https://api.github.com/repos/${param.repository_owner}/${param.repository_name}/git/refs/heads/${param.branch_name}"
request_headers = {
Authorization = "Bearer ${credential.github[param.cred].token}"
}

throw {
if = can(result.response_body.errors)
message = join(", ", flatten([for error in result.response_body.errors : error.message]))
}
}

output "branch" {
value = step.http.delete_branch
}

}
40 changes: 40 additions & 0 deletions pipelines/branch/get_branch.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pipeline "get_branch" {
title = "Get branch"
description = "Get a branch in a specified repository."

param "cred" {
type = string
default = "default"
}

param "repository_owner" {
type = string
description = local.repository_owner_param_description
}

param "repository_name" {
type = string
description = local.repository_name_param_description
}

param "branch_name" {
type = string
description = "The name of the branch to check."
}

step "http" "get_branch" {
method = "get"
url = "https://api.github.com/repos/${param.repository_owner}/${param.repository_name}/branches/${param.branch_name}"
request_headers = {
Authorization = "Bearer ${credential.github[param.cred].token}"
}
error {
ignore = true
}
}

output "branch" {
value = step.http.get_branch
}

}
65 changes: 65 additions & 0 deletions pipelines/branch/tests/test_branch_operations.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
pipeline "test_branch_operations" {
title = "Test Branch Operations"
description = "Test the create_branch, get_branch, and delete_branch pipelines."

tags = {
type = "test"
}

param "cred" {
type = string
description = local.cred_param_description
default = "default"
}

param "repository_owner" {
type = string
}

param "repository_name" {
type = string
}

param "branch_name" {
type = string
}

step "transform" "args" {
value = {
cred = param.cred
repository_owner = param.repository_owner
repository_name = param.repository_name
branch_name = param.branch_name
}
}

step "pipeline" "create_branch" {
pipeline = pipeline.create_branch
args = step.transform.args.value
}

step "pipeline" "get_branch" {
depends_on = [step.pipeline.create_branch]
pipeline = pipeline.get_branch
args = step.transform.args.value
}

step "pipeline" "delete_branch" {
depends_on = [step.pipeline.get_branch]
pipeline = pipeline.delete_branch
args = step.transform.args.value
}

output "check_create_branch" {
value = step.pipeline.create_branch.output.branch.status_code == 201 ? "pass" : "fail"
}

output "check_get_branch" {
value = step.pipeline.get_branch.output.branch.status_code == 200 ? "pass" : "fail"
}

output "check_delete_branch" {
value = step.pipeline.delete_branch.output.branch.status_code == 204 ? "pass" : "fail"
}

}

0 comments on commit 88994a3

Please sign in to comment.