使用 Atlassian Bitbucket API 从存储库获取文件
我有一个使用 Atlassian Bitbucket API 实现挂钩的 Java 应用程序。
实现该钩子的类定义如下:
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHook;
import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookRequest;
import com.atlassian.bitbucket.repository.Repository;
import javax.annotation.Nonnull;
/* Other imports */
@ExportAsService({SCMAdapter.class})
public class SCMAdapter implements PreRepositoryHook<RepositoryHookRequest>, ISCMAdapter{
/*Methods from both interfaces*/
}
ISCMAdapter
接口中的方法与此问题无关。
PreRepositoryHook
接口包含两个方法。其中之一如下:
public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context, @Nonnull RepositoryHookRequest request){
/*Returns a RepositoryHookResult object */
}
我可以通过以下调用获取挂钩中涉及的存储库:
Repository repo = request.getRepository();
从该对象,我可以获取项目的密钥、slug、ID、名称和状态:
String pkey=repo.getProject().getKey();
String slug=repo.getSlug();
String name=repo.getName();
int id=repo.getId();
Repository.State state=repo.getState();
该方法当前工作正常。但是,我要求每个存储库必须有一个所有存储库同名的隐藏目录(假设为“.myHiddenDir”),并且该目录必须包含一个名为 config.yml 的 YAML 文件
是否可能,获取的信息为上面列出来获取存储库中特定文件的内容?
提前致谢。
PD:如果您发现此描述缺少更多信息,请告诉我,我会检查代码。
I have a Java Application that implements a hook using the Atlassian Bitbucket API.
The class that implements the hook is defined as follows:
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHook;
import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookRequest;
import com.atlassian.bitbucket.repository.Repository;
import javax.annotation.Nonnull;
/* Other imports */
@ExportAsService({SCMAdapter.class})
public class SCMAdapter implements PreRepositoryHook<RepositoryHookRequest>, ISCMAdapter{
/*Methods from both interfaces*/
}
The methods from the ISCMAdapter
interface are irrelevant for this problem.
The PreRepositoryHook
interface contains two methods. One of them is the following:
public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context, @Nonnull RepositoryHookRequest request){
/*Returns a RepositoryHookResult object */
}
I can obtain the repository involved in the hook with the following call:
Repository repo = request.getRepository();
From that object, I can obtain the project's key, the slug, the ID, the name and the state:
String pkey=repo.getProject().getKey();
String slug=repo.getSlug();
String name=repo.getName();
int id=repo.getId();
Repository.State state=repo.getState();
The method is currently working fine. However, I got a requirement that each repository must have a hidden directory with the same name for all repositories (lets say ".myHiddenDir") and that directory must contain a YAML file named config.yml
Is it possible, with the information obtained as listed above to obtain the content of an specific file in the repo?
Thanks in advance.
P.D.: If you find that this description is lacking more info, please let me know and I will check the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论