@@ -49,13 +49,16 @@ class ConfigurationVersion(Base, BaseObject):
49
49
auto_queue_runs = sqlalchemy .Column (sqlalchemy .Boolean )
50
50
status = sqlalchemy .Column (sqlalchemy .Enum (ConfigurationVersionStatus ))
51
51
52
+ git_commit_sha = sqlalchemy .Column (Database .GeneralString , nullable = True )
53
+
52
54
@classmethod
53
- def create (cls , workspace , auto_queue_runs = True , speculative = False ):
55
+ def create (cls , workspace , auto_queue_runs = True , speculative = False , git_commit_sha = None ):
54
56
"""Create configuration and return instance."""
55
57
cv = ConfigurationVersion (
56
58
workspace = workspace ,
57
59
speculative = speculative ,
58
60
auto_queue_runs = auto_queue_runs ,
61
+ git_commit_sha = git_commit_sha ,
59
62
status = ConfigurationVersionStatus .PENDING
60
63
)
61
64
session = Database .get_session ()
@@ -67,22 +70,19 @@ def create(cls, workspace, auto_queue_runs=True, speculative=False):
67
70
return cv
68
71
69
72
@classmethod
70
- def generate_from_vcs (cls , workspace , speculative ):
73
+ def generate_from_vcs (cls , workspace , speculative , commit_ref = None ):
71
74
"""Create configuration version from VCS"""
72
75
service_provider = workspace .authorised_repo .oauth_token .oauth_client .service_provider_instance
73
76
74
- # Obtain branch from workspace
75
- branch = workspace .vcs_repo_branch
76
- # If it doesn't exist, obtain default branch from repository
77
- if not branch :
78
- branch = service_provider .get_default_branch (authorised_repo = workspace .authorised_repo )
79
-
80
- if not branch :
81
- return None
82
-
83
- commit_ref = service_provider .get_latest_commit_ref (
84
- authorised_repo = workspace .authorised_repo , branch = branch
85
- )
77
+ if commit_ref is None :
78
+ # Obtain branch from workspace
79
+ branch = workspace .get_branch ()
80
+ if not branch :
81
+ return None
82
+
83
+ commit_ref = service_provider .get_latest_commit_ref (
84
+ authorised_repo = workspace .authorised_repo , branch = branch
85
+ )
86
86
if commit_ref is None :
87
87
return None
88
88
@@ -94,12 +94,22 @@ def generate_from_vcs(cls, workspace, speculative):
94
94
95
95
configuration_version = cls .create (
96
96
workspace = workspace ,
97
- auto_queue_runs = False ,
98
- speculative = speculative
97
+ auto_queue_runs = True ,
98
+ speculative = speculative ,
99
+ git_commit_sha = commit_ref
99
100
)
100
101
configuration_version .process_upload (archive_data )
101
102
return configuration_version
102
103
104
+ @classmethod
105
+ def get_configuration_version_by_git_commit_sha (cls , workspace , git_commit_sha ):
106
+ """Return configuration versions by workspace and git commit sha"""
107
+ session = Database .get_session ()
108
+ return session .query (cls ).filter (
109
+ cls .workspace == workspace ,
110
+ cls .git_commit_sha == git_commit_sha
111
+ ).all ()
112
+
103
113
@property
104
114
def plan_only (self ):
105
115
"""Return whether only a plan."""
0 commit comments