有没有一种方法可以使用命令确定 GitLab 中的分支是否受到保护git?
最好是一种确定受保护状态的方法,而无需尝试做非法的事情并收到警告。
以下测试失败,NullPointerException并在线上显示usersRepo.save(user);。我相信这是因为当测试进入performProvision()功能时,usersRepo对象就是null。
但是,当Web服务实际上正在运行并且控制器的端点被命中时,一切正常,并且数据库已更新。
知道为什么测试失败了吗?我的想法是PAutoProvision引用真实的数据库,而它应该处理内存数据库,所以也许存在某种冲突?我还看到了很多不同的示例,它们的注释设置不同,所以我想这可能也是一个问题。
UsersRepo扩展了JpaRepository,其中PAutoProvision是一个SQL表实体。
如果没有足够的信息,我可以提供的UsersRepo,PAutoProvision以及ProvisionController如果必要的类。
服务:
@Service
public class ProvisionService {
@Autowired
private UsersRepo usersRepo;
public String performProvision(UserData userData) {
try {
PAutoProvision user = new PAutoProvision(userData);
usersRepo.save(user); // OOTB CRUD repository functionality of springData to update/insert record data
return String.format("Success: User %s has been added to the database", userData.getUserId());
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.toString());
System.out.println("\n\n Cannot perform the provisioning …Run Code Online (Sandbox Code Playgroud) 我在这里使用以下命令:
git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p) %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes
Run Code Online (Sandbox Code Playgroud)
有没有办法authordate按特定日期排序?
例如,仅显示 X 天或几个月前的结果,或者可能是在给定日期之后的结果?我正在考虑使用,grep但我希望有一种方法可以实际解析给定的日期来进行计算,而不仅仅是字符串匹配。
我想出了以下使用方法sed:
git for-each-ref --format='%(color:cyan)%(authordate:format:%Y-%m-%d %I:%M %p) %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes | sed -n '/{start_year}-*/,/{end_year}-{end_month}-*/p'
Run Code Online (Sandbox Code Playgroud)
但最好只给出一个特定日期并获得该日期之前或之后的所有结果。
编辑:如果给定的结束日期不存在,上面使用的方法sed将不起作用,因为 sed 只是一个流编辑器。例如,如果生成的 sed 字符串是,'/2017-*/,/2018-10-*/p'但没有匹配的条目2018-10-*(2018 年 10 月没有提交的分支),那么它将获得 2017 年以后的所有结果。也就是说,它不是真正的日期范围计算;这是一个简单的字符串匹配,当它找到与右侧匹配的第一个条目时停止。
我编写了一个函数,它使用底数 b 和指数 e 进行幂运算,如下所示:
fun power b e = if e = 0 then 1 else b * power b (e-1);
Run Code Online (Sandbox Code Playgroud)
显然,这适用于整数,如输出所示:
val power = fn : int -> int -> int
Run Code Online (Sandbox Code Playgroud)
但是,我希望它为 b 取一个实数,为 e 取一个整数。我尝试使用以下内容:
fun power (b : real) (e : int) = if e = 0 then 1 else b * power b (e-1);
Run Code Online (Sandbox Code Playgroud)
虽然这给了我错误。任何帮助表示赞赏。
与此类似的问题,但我知道什么是任务,并且找不到标签和角色之间的太多区别。
在我看来,标签可能是角色的更简单版本,它们的唯一用途是通过--tags和--skip-tagsCLI 参数访问。
另一方面,角色用于“自动加载”任务和变量之类的东西吗?
请解释使用角色的好处,因为在我看来,角色要求您为不同的部分(任务、变量等)使用不同的 yaml 文件,我可以使用includeandtags
指令以更少的代码完成。
我有一个任务应该运行 SQL 脚本列表。如果在执行序列中的任何脚本期间出现错误,则任务应停止执行。
给定以下任务,是否有一种方法可以修改它以查看循环当前迭代的寄存器的标准输出,以检查是否'ERROR'在标准输出中?
- name: Build and run SQLPlus commands
shell: 'echo @{{ item }} | {{ sqlplus }} {{ db_user }}/{{ db_pass }}@{{ environment }}'
register: sh1
with_items:
- ["a.sql", "b.sql"]
# failed_when: "'ERROR' in sh1.stdout_lines"
Run Code Online (Sandbox Code Playgroud)
我正在思考最后一条注释行的内容,但由于sh1是来自循环任务的寄存器变量,因此每个 SQL 脚本的输出都位于;列表 results中。sh1所以我不确定如何访问刚刚执行的命令的特定标准输出。
我正在Unity3D项目中处理一个C#脚本,我正在尝试获取字符串列表并获得排列的2D列表.以下列方式使用此答案 GetPermutations():
List<string> ingredientList = new List<string>(new string[] { "ingredient1", "ingredient2", "ingredient3" });
List<List<string>> permutationLists = GetPermutations(ingredientList, ingredientList.Count);
Run Code Online (Sandbox Code Playgroud)
但它会引发隐式转换错误:
IEnumerable<IEnumerable<string>> to List<List<string>> ... An explicit conversion exists (are you missing a cast)?
所以我看了几个地方,比如这里,并提出了以下修改:
List<List<string>> permutationLists = GetPermutations(ingredientList, ingredientList.Count).Cast<List<string>>().ToList();
Run Code Online (Sandbox Code Playgroud)
但它在运行时中断,在内部处理,并允许它继续而不指示失败 - 可能是因为它在Unity3D中运行.这是我在停止调试脚本后在Unity3D中看到的内容:
InvalidCastException: Cannot cast from source type to destination type.
System.Linq.Enumerable+<CreateCastIterator>c__Iterator0`1[System.Collections.Generic.List`1[System.String]].MoveNext ()
System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]].AddEnumerable (IEnumerable`1 enumerable) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:128)
System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]]..ctor (IEnumerable`1 collection) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:65)
System.Linq.Enumerable.ToList[List`1] (IEnumerable`1 source)
Run Code Online (Sandbox Code Playgroud)
我认为这仍然是错误的,所以我也尝试了以下方法和更多我不记得的方法:
List<List<string>> permutationLists = GetPermutations(ingredientList, ingredientList.Count).Cast<List<List<string>>>();
List<List<string>> permutationLists = GetPermutations(ingredientList.AsEnumerable(), ingredientList.Count); …Run Code Online (Sandbox Code Playgroud)