Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

pointgoal/workstation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents generated with DocToc

workstation

build Go Report Card codecov License

Workstation backend.

Quick start

Start workstation by running bellow command or right click main.go file on your IDE.

$ go run main.go

Backend repository

Currently, we support one types of repository which is MySql.

MySql

Configure workstation to use mysql as backend repository

  • boot.yaml
---
...
repository:
  enabled: true
  provider: mySql
  mySql:
    user: root
    pass: pass
    protocol: tcp
    addr: localhost:3306
    params:
      - "charset=utf8mb4"
      - "parseTime=True"
      - "loc=Local"

API

Organizations

API Description
GET /v1/org List organizations
PUT /v1/org Create organization
GET /v1/org/{orgId} Get organization
POST /v1/org/{orgId} Update organization
DELETE /v1/org/{orgId} Delete organization

List organizations

$ curl -X GET "http://localhost:8080/v1/org"
{
  "orgList": [
    {
      "meta": {
        "id": 1,
        "createdAt": "2021-10-08T00:48:12.523+08:00",
        "updatedAt": "2021-10-08T00:48:12.523+08:00",
        "name": "org-1"
      },
      "projIds": [
        1,
        2
      ]
    },
    {
      "meta": {
        "id": 2,
        "createdAt": "2021-10-08T00:48:19.742+08:00",
        "updatedAt": "2021-10-08T00:48:19.742+08:00",
        "name": "org-2"
      },
      "projIds": []
    }
  ]
}

Create organization

$ curl -X PUT "http://localhost:8080/v1/org?orgName=my-org-5"
{
  "orgId": 3
}

Get organization

$ curl -X GET "http://localhost:8080/v1/org/1"
{
  "org": {
    "meta": {
      "id": 1,
      "createdAt": "2021-10-08T00:48:12.523+08:00",
      "updatedAt": "2021-10-08T00:48:12.523+08:00",
      "name": "org-1"
    },
    "projIds": [
      1,
      2
    ]
  }
}

Update organization

$ curl -X POST "http://localhost:8080/v1/org/4" -d "{  \"name\": \"my-new-org-4\"}"
{
  "status": true
}

Delete organization

$ curl -X DELETE "http://localhost:8080/v1/org/4"
{
  "status": true
}

Projects

API Description
GET /v1/proj?orgId=? List projects
PUT /v1/proj Create project
GET /v1/proj/{projId} Get project
POST /v1/proj/{projId} Update project
DELETE /v1/proj/{projId} Delete project

List projects

$ curl -X GET "http://localhost:8080/v1/org/1/proj"
{
  "projList": [
    {
      "meta": {
        "id": 1,
        "createdAt": "2021-10-08T00:49:07.928+08:00",
        "updatedAt": "2021-10-08T00:49:07.928+08:00",
        "orgId": 1,
        "name": "proj-1"
      }
    },
    {
      "meta": {
        "id": 2,
        "createdAt": "2021-10-08T00:50:09.859+08:00",
        "updatedAt": "2021-10-08T00:50:09.859+08:00",
        "orgId": 1,
        "name": "proj-2"
      }
    }
  ]
}

Create project

$ curl -X PUT "http://localhost:8080/v1/proj?ordId=3" -d "{  \"name\": \"my-proj-4\"}"
{
  "orgId": 3,
  "projId": 3
}

Get project

$ curl -X GET "http://localhost:8080/v1/proj/3"
{
  "proj": {
    "meta": {
      "id": 3,
      "createdAt": "2021-10-08T16:39:08.794+08:00",
      "updatedAt": "2021-10-08T16:39:08.794+08:00",
      "orgId": 3,
      "name": "my-proj-4"
    }
  }
}

Update project

$ curl -X POST "http://localhost:8080/v1/proj/3" -d "{  \"name\": \"my-new-proj\"}"
{
  "status": true
}

Delete project

$ curl -X DELETE "http://localhost:8080/v1/proj/3"
{
  "status": true
}

Source

API Description
PUT /v1/source?projId=? Create source
DELETE /v1/source/{sourceId} Delete source

Create source

$ curl -X PUT "http://localhost:8080/v1/source?projId=1" -d "{  \"repository\": \"repo-1\",  \"type\": \"github\"}"
{
  "projId": 1,
  "sourceId": 1
}

Delete source

$ curl -X DELETE "http://localhost:8080/v1/source/1"
{
  "status": true
}

Oauth

Provide oauth callback API, please do not call it manually.

It should be called from code repositories.

github

GET /v1/oauth/callback/github

Installations

List installations from code repo.

API Description
GET /v1/user/installations?source=?&user=? List installations from remote code repo
GET /v1/source/{sourceId}/commits?branch=?&perPage=?&page=? List user installation commits
GET /v1/source/{sourceId}/branches?perPage=?&page=? List branches and tags

Github

User should make sure access token was stored in backend DB first.

User need to install workstation from Web UI which will store access token automatically.

$ curl -X GET "http://localhost:8080/v1/user/installations?source=github&user=dongxuny"
[
  {
    "repoSource": "github",
    "organization": "dongxuny",
    "avatarUrl": "https://avatars.githubusercontent.com/u/50768414?v=4",
    "repos": [
      {
        "fullName": "dongxuny/awesome-go",
        "name": "awesome-go"
      }
    ]
  },
  {
    "repoSource": "github",
    "organization": "pointgoal",
    "avatarUrl": "https://avatars.githubusercontent.com/u/90323078?v=4",
    "repos": [
      {
        "fullName": "pointgoal/community",
        "name": "community"
      }
    ]
  }
]

List commits from github

$ curl -X GET "http://localhost:8080/v1/source/2/commits?branch=master&perPage=1" -H  "accept: application/json"
{
  "commits": [
    {
      "id": "2ab83470e96b196f7f365225ac5bc6bec7d7f8f7",
      "url": "https://github.com/rookie-ninja/rk-boot/commit/2ab83470e96b196f7f365225ac5bc6bec7d7f8f7",
      "message": "Merge pull request #12 from dongxuny/master\n\nAdd build and test instructions in README.md",
      "date": "2021-10-19T05:30:38Z",
      "committer": "GitHub",
      "committerUrl": "https://github.com/web-flow",
      "artifact": null
    }
  ]
}

List branches and tags from github

$ curl -X GET "http://localhost:8080/v1/source/2/branches" -H  "accept: application/json"
{
  "branches": [
    "master"
  ],
  "tags": [
    "v1.2.6",
    "v1.2.5",
    "v1.2.4",
    "v1.2.3",
    "v1.2.2",
    "v1.2.1",
    "v1.2.0",
    "v1.1.2",
    "v1.1.1",
    "v1.1.0"
  ]
}