Skip to content

Commit

Permalink
added support for git clone params in schema from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
godfryd committed Sep 15, 2021
1 parent 22e6b14 commit 3e48271
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""added git_clone_params to stage
Revision ID: 54efe873f88f
Revises: e0d8421619c2
Create Date: 2021-09-15 06:40:12.583695
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '54efe873f88f'
down_revision = 'e0d8421619c2'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('stages', sa.Column('git_clone_params', sa.UnicodeText(), nullable=True))


def downgrade():
op.drop_column('stages', 'git_clone_params')
3 changes: 2 additions & 1 deletion server/kraken/server/bg/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ def refresh_schema_repo(stage_id, complete_starting_run_id=None):

try:
# get schema from repo
schema_code, version = gitops.get_schema_from_repo(stage.repo_url, stage.repo_branch, stage.repo_access_token, stage.schema_file)
schema_code, version = gitops.get_schema_from_repo(stage.repo_url, stage.repo_branch, stage.repo_access_token,
stage.schema_file, stage.git_clone_params)

# check schema
schema_code, schema = check_and_correct_stage_schema(stage.branch, stage.name, schema_code)
Expand Down
4 changes: 2 additions & 2 deletions server/kraken/server/gitops.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ def get_repo_commits_since(branch_id, prev_run, repo_url, repo_branch, git_cfg):
return commits, base_commit


def get_schema_from_repo(repo_url, repo_branch, repo_access_token, schema_file): # pylint: disable=unused-argument
def get_schema_from_repo(repo_url, repo_branch, repo_access_token, schema_file, git_clone_params): # pylint: disable=unused-argument
with tempfile.TemporaryDirectory(prefix='kraken-git-') as tmpdir:
# clone repo
cmd = "git clone --depth 1 --single-branch --branch %s '%s' repo" % (repo_branch, repo_url)
cmd = "git clone --depth 1 --single-branch --branch %s %s '%s' repo" % (repo_branch, git_clone_params, repo_url)
p = _run(cmd, check=False, cwd=tmpdir, capture_output=True, text=True)
if p.returncode != 0:
err = "command '%s' returned non-zero exit status %d\n" % (cmd, p.returncode)
Expand Down
5 changes: 4 additions & 1 deletion server/kraken/server/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def create_branch(project_id, body):
repo_url=stage.repo_url,
schema_file=stage.schema_file,
schema_from_repo_enabled=stage.schema_from_repo_enabled,
repo_refresh_interval=stage.repo_refresh_interval)
repo_refresh_interval=stage.repo_refresh_interval,
git_clone_params=stage.git_clone_params)

if body['forking_model'] == 'model-1':
# forked branch continues numbering, old branch resets numbering
Expand Down Expand Up @@ -372,6 +373,8 @@ def update_stage(stage_id, body):
abort(400, 'Incorrect repo refresh interval value')
stage.repo_refresh_interval = body['repo_refresh_interval']
log.info('stage.repo_refresh_interval %s', stage.repo_refresh_interval)
if 'git_clone_params' in body:
stage.git_clone_params = body['git_clone_params']

stage.repo_state = consts.REPO_STATE_REFRESHING
stage.repo_error = ''
Expand Down
2 changes: 2 additions & 0 deletions server/kraken/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Stage(db.Model, DatesMixin):
repo_access_token = Column(UnicodeText)
repo_branch = Column(UnicodeText)
repo_url = Column(UnicodeText)
git_clone_params = Column(UnicodeText)
schema_file = Column(UnicodeText)
schema_from_repo_enabled = Column(Boolean, default=False)
repo_error = Column(UnicodeText)
Expand All @@ -235,6 +236,7 @@ def get_json(self, with_schema=True):
repo_state=self.repo_state,
repo_error=self.repo_error,
repo_refresh_interval=self.repo_refresh_interval,
git_clone_params=self.git_clone_params,
repo_version=self.repo_version,
schema_file=self.schema_file)

Expand Down
3 changes: 3 additions & 0 deletions ui/src/app/branch-mgmt/branch-mgmt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@
<label for="repo_refresh_interval"><span>Refresh Interval</span>
<input type="text" class="input-field" name="repo_refresh_interval" pInputText formControlName="repo_refresh_interval"/>
</label>
<label for="git_clone_params"><span>Git Clone Params</span>
<input type="text" class="input-field" name="git_clone_params" pInputText formControlName="git_clone_params"/>
</label>
</form>
</div>
</p-tabPanel>
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/branch-mgmt/branch-mgmt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class BranchMgmtComponent implements OnInit {
repo_access_token: new FormControl(''),
schema_file: new FormControl(''),
repo_refresh_interval: new FormControl(''),
git_clone_params: new FormControl(''),
})

sequences = []
Expand Down Expand Up @@ -148,6 +149,7 @@ export class BranchMgmtComponent implements OnInit {
repo_access_token: stage.repo_access_token,
schema_file: stage.schema_file,
repo_refresh_interval: stage.repo_refresh_interval,
git_clone_params: stage.git_clone_params,
}
this.schemaFromRepoForm.setValue(val)

Expand Down

0 comments on commit 3e48271

Please sign in to comment.